Class: Report::PhoneQueueReportCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::PhoneQueueReportCommand
- Defined in:
- app/services/report/phone_queue_report_command.rb
Overview
Command pattern to encapsulate parameters necessary to run a presence report
Constant Summary collapse
- GROUPING_OPTIONS =
%w[year month day week quarter hour].freeze
Instance Method Summary collapse
- #execute(queue_params = nil) ⇒ Object
- #operator_options ⇒ Object
- #period1_humanized ⇒ Object
- #period1_range ⇒ Object
- #to_csv(queue_params = nil) ⇒ Object
Instance Method Details
#execute(queue_params = nil) ⇒ Object
20 21 22 23 24 |
# File 'app/services/report/phone_queue_report_command.rb', line 20 def execute(queue_params = nil) return unless valid? @results = Analytic::PhoneRecordFact.get_queue_results(queue_params.presence || default_query_params) end |
#operator_options ⇒ Object
16 17 18 |
# File 'app/services/report/phone_queue_report_command.rb', line 16 def QueueCallLog.where.not(member_name: nil).pluck('distinct member_name'.sql_safe).sort end |
#period1_humanized ⇒ Object
46 47 48 |
# File 'app/services/report/phone_queue_report_command.rb', line 46 def period1_humanized "From #{period1_range.first} until #{period1_range.last}" end |
#period1_range ⇒ Object
42 43 44 |
# File 'app/services/report/phone_queue_report_command.rb', line 42 def period1_range period1_gteq && period1_lteq && period1_gteq..period1_lteq end |
#to_csv(queue_params = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/report/phone_queue_report_command.rb', line 26 def to_csv(queue_params = nil) return unless valid? @results ||= Analytic::PhoneRecordFact.get_queue_results(queue_params.presence || default_query_params) return if @results.individuals.blank? attributes = @results.individuals.first.attributes.keys CSV.generate(headers: true) do |csv| csv << attributes @results.individuals.each do |r| csv << attributes.map { |attr| r.send(attr) } end end end |