Class: Report::ItemSale::ItemSaleCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::ItemSale::ItemSaleCommand
- 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
-
#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.
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.
46 47 48 |
# File 'app/services/report/item_sale/item_sale_command.rb', line 46 def success? valid? && @result.success? end |
#to_csv ⇒ String
Render the report rows as CSV.
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 |