Class: Report::ItemSale::ItemSaleCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
app/services/report/item_sale/item_sale_command.rb

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Instance Method Summary collapse

Instance Method Details

#executeObject

Run the report with the given filters and store the result.

Returns:

  • (Object)


21
22
23
24
25
# File 'app/services/report/item_sale/item_sale_command.rb', line 21

def execute
  return unless valid?

  @result = Report::ItemSale::ItemSale.total_report(attributes)
end

#success?Boolean

Whether the command validated and ran successfully.

Returns:

  • (Boolean)


46
47
48
# File 'app/services/report/item_sale/item_sale_command.rb', line 46

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

#to_csvString

Render the report rows as CSV.

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/report/item_sale/item_sale_command.rb', line 29

def to_csv
  return unless valid?

  @result = Report::ItemSale::ItemSale.total_report(attributes)
  return if @result.data_table.blank?

  attributes = @result.data_table.first.keys
  CSV.generate(headers: true) do |csv|
    csv << attributes
    @result.data_table.each do |r|
      csv << r
    end
  end
end