Class: Report::ItemMovedToScrap::ItemMovedToScrapReportCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::ItemMovedToScrap::ItemMovedToScrapReportCommand
- Defined in:
- app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb
Overview
Command pattern to encapsulate parameters necessary to run a report
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
13 14 15 16 17 |
# File 'app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb', line 13 def execute return unless valid? @result = Report::ItemMovedToScrap::ItemMovedToScrapReport.result_report(attributes) end |
#success? ⇒ Boolean
35 36 37 |
# File 'app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb', line 35 def success? valid? && @result.success? end |
#to_csv ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb', line 19 def to_csv return unless valid? @result = Report::ItemMovedToScrap::ItemMovedToScrapReport.result_report(attributes) return if @result.data.blank? attributes = @result.data.first.attributes.keys CSV.generate(headers: true) do |csv| csv << attributes @result.data.each do |r| csv << attributes.map { |attr| r.send(attr) } end end end |