Class: Report::CallStatistics::Command

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

Overview

Service object: command.

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

Methods included from Heatwave::AttributeNormalizing

normalize

Constructor Details

This class inherits a constructor from Report::BaseCommand

Instance Method Details

#departments=(new_departments) ⇒ Object

Set the departments.

Parameters:

  • new_departments (Object)

Returns:

  • (Object)


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.

Parameters:

  • new_employee_ids (Array<Integer>)

Returns:

  • (Object)


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

#executeObject

Run the report with the given filters and store the result.

Returns:

  • (Object)


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.

Returns:

  • (Boolean)


56
57
58
# File 'app/services/report/call_statistics/command.rb', line 56

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

#to_csvString

Render the report rows as CSV.

Returns:

  • (String)


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