Class: Report::ShippingRates::ShippingRatesCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
app/services/report/shipping_rates/shipping_rates_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



7
8
9
10
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 7

def execute
  return unless valid?
  @result = Report::ShippingRates::ShippingRates.result(attributes)
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 25

def success?
  valid? && @result.success?
end

#to_csvObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/report/shipping_rates/shipping_rates_command.rb', line 12

def to_csv
  return unless valid?
  @result = Report::ShippingRates::ShippingRates.result(attributes)
  return unless @result.shipping_rates.present?
  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