Class: Report::LeadReport::LeadReportCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::LeadReport::LeadReportCommand
- Defined in:
- app/services/report/lead_report/lead_report_command.rb
Overview
Service object: lead report command.
Instance Method Summary collapse
-
#execute(type) ⇒ Object
Run the report with the given filters and store the result.
-
#success? ⇒ Boolean
Whether the command validated and ran successfully.
-
#to_calls_csv ⇒ Object
To calls csv.
-
#to_communications_csv ⇒ Object
To communications csv.
-
#to_customers_csv ⇒ Object
To customers csv.
-
#to_opportunities_csv ⇒ Object
To opportunities csv.
-
#to_orders_csv ⇒ Object
To orders csv.
-
#to_rooms_csv ⇒ Object
To rooms csv.
-
#to_services_csv ⇒ Object
To services csv.
-
#to_sms_csv ⇒ Object
To sms csv.
-
#to_website_visits_csv ⇒ Object
To website visits csv.
Instance Method Details
#execute(type) ⇒ Object
Run the report with the given filters and store the result.
14 15 16 17 18 19 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 14 def execute(type) return unless valid? @result = Report::LeadReport::LeadReport.results(attributes, type) if type == 'customer' @result = Report::LeadReport::LeadReport.results(attributes, type) if type == 'opportunities' end |
#success? ⇒ Boolean
Whether the command validated and ran successfully.
176 177 178 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 176 def success? valid? && @result.success? end |
#to_calls_csv ⇒ Object
To calls csv.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 108 def to_calls_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.calls.blank? attributes = @result.calls.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.calls.each do |r| csv << r end end end |
#to_communications_csv ⇒ Object
To communications csv.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 125 def to_communications_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.communications.blank? attributes = @result.communications.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.communications.each do |r| csv << r end end end |
#to_customers_csv ⇒ Object
To customers csv.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 23 def to_customers_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.customer_created.blank? attributes = @result.customer_created.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.customer_created.each do |r| csv << r end end end |
#to_opportunities_csv ⇒ Object
To opportunities csv.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 40 def to_opportunities_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.opportunities_created.blank? attributes = @result.opportunities_created.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.opportunities_created.each do |r| csv << r end end end |
#to_orders_csv ⇒ Object
To orders csv.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 57 def to_orders_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.orders_created.blank? attributes = @result.orders_created.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.orders_created.each do |r| csv << r end end end |
#to_rooms_csv ⇒ Object
To rooms csv.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 91 def to_rooms_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.rooms_created.blank? attributes = @result.rooms_created.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.rooms_created.each do |r| csv << r end end end |
#to_services_csv ⇒ Object
To services csv.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 74 def to_services_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.services_by_pl.blank? attributes = @result.services_by_pl.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.services_by_pl.each do |r| csv << r end end end |
#to_sms_csv ⇒ Object
To sms csv.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 142 def to_sms_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.sms.blank? attributes = @result.sms.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.sms.each do |r| csv << r end end end |
#to_website_visits_csv ⇒ Object
To website visits csv.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/services/report/lead_report/lead_report_command.rb', line 159 def to_website_visits_csv return unless valid? @result = Report::LeadReport::LeadReport.results(attributes) return if @result.website_visits.blank? attributes = @result.website_visits.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.website_visits.each do |r| csv << r end end end |