Class: Report::CallStatistics::Command

Inherits:
BaseCommand show all
Defined in:
app/services/report/call_statistics/command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ARRAY_TYPE_NAMES

Instance Attribute Summary

Attributes inherited from BaseCommand

#results

Instance Method Summary collapse

Methods inherited from BaseCommand

#attributes, #email_parameters, #email_partial, #initialize

Constructor Details

This class inherits a constructor from Report::BaseCommand

Instance Method Details

#departments=(new_departments) ⇒ Object



13
14
15
# File 'app/services/report/call_statistics/command.rb', line 13

def departments=(new_departments)
  super (new_departments || []).map(&:presence).compact.uniq
end

#employee_ids=(new_employee_ids) ⇒ Object



17
18
19
# File 'app/services/report/call_statistics/command.rb', line 17

def employee_ids=(new_employee_ids)
  super (new_employee_ids || []).map(&:presence).compact.uniq
end

#executeObject



21
22
23
24
# File 'app/services/report/call_statistics/command.rb', line 21

def execute
  return unless valid?
  @result = Query.report(attributes.symbolize_keys)
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/services/report/call_statistics/command.rb', line 40

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

#to_csvObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/report/call_statistics/command.rb', line 26

def to_csv
  return unless valid?
  @result = Query.report(attributes.symbolize_keys)
  return unless @result.individuals.present?
  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