Class: Report::CallStatistics::Command
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::CallStatistics::Command
- Defined in:
- app/services/report/call_statistics/command.rb
Overview
Service object: command.
Constant Summary
Constants inherited from BaseCommand
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#departments=(new_departments) ⇒ Object
Set the departments.
-
#employee_ids=(new_employee_ids) ⇒ Object
Set the employee ids.
-
#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.
Methods inherited from BaseCommand
#[], #attributes, #email_parameters, #email_partial, #initialize
Methods included from Heatwave::AttributeNormalizing
Constructor Details
This class inherits a constructor from Report::BaseCommand
Instance Method Details
#departments=(new_departments) ⇒ Object
Set the departments.
17 18 19 |
# File 'app/services/report/call_statistics/command.rb', line 17 def departments=(new_departments) super((new_departments || []).filter_map(&:presence).uniq) end |
#employee_ids=(new_employee_ids) ⇒ Object
Set the employee ids.
24 25 26 |
# File 'app/services/report/call_statistics/command.rb', line 24 def employee_ids=(new_employee_ids) super((new_employee_ids || []).filter_map(&:presence).uniq) end |
#execute ⇒ Object
Run the report with the given filters and store the result.
30 31 32 33 34 |
# File 'app/services/report/call_statistics/command.rb', line 30 def execute return unless valid? @result = Query.report(attributes.symbolize_keys) end |
#success? ⇒ Boolean
Whether the command validated and ran successfully.
56 57 58 |
# File 'app/services/report/call_statistics/command.rb', line 56 def success? valid? && @result.success? end |
#to_csv ⇒ String
Render the report rows as CSV.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/report/call_statistics/command.rb', line 38 def to_csv return unless valid? @result = Query.report(attributes.symbolize_keys) return if @result.individuals.blank? attributes = @result.individuals.first.attributes.keys CSV.generate(headers: true) do |csv| csv << attributes @result.individuals.each do |r| csv << attributes.map { |attr| r.send(attr) } end end end |