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 |
# 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
32 33 34 |
# File 'app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb', line 32 def success? valid? && @result.success? end |
#to_csv ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/report/item_moved_to_scrap/item_moved_to_scrap_report_command.rb', line 18 def to_csv return unless valid? @result = Report::ItemMovedToScrap::ItemMovedToScrapReport.result_report(attributes) return unless @result.data.present? 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 |