Class: Report::ShippingRates::ShippingRatesCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::ShippingRates::ShippingRatesCommand
- Defined in:
- app/services/report/shipping_rates/shipping_rates_command.rb
Overview
Service object: shipping rates command.
Instance Method Summary collapse
-
#execute ⇒ Object
Run the report with the given filters and store the result.
-
#success? ⇒ Boolean
Whether the command validated and ran successfully.
-
#to_csv ⇒ String
Render the report rows as CSV.
Instance Method Details
#execute ⇒ Object
Run the report with the given filters and store the result.
10 11 12 13 14 |
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 10 def execute return unless valid? @result = Report::ShippingRates::ShippingRates.result(attributes) end |
#success? ⇒ Boolean
Whether the command validated and ran successfully.
35 36 37 |
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 35 def success? valid? && @result.success? end |
#to_csv ⇒ String
Render the report rows as CSV.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 18 def to_csv return unless valid? @result = Report::ShippingRates::ShippingRates.result(attributes) return if @result.shipping_rates.blank? attributes = @result.shipping_rates.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.shipping_rates.each do |r| csv << r end end end |