Class: Spree::Report::Result
- Inherits:
-
Object
- Object
- Spree::Report::Result
show all
- Defined in:
- app/reports/spree/report/result.rb
Direct Known Subclasses
BestSellingProductsReport::Result, CartAdditionsReport::Result, CartRemovalsReport::Result, CartUpdationsReport::Result, ProductViewsReport::Result, ProductViewsToCartAdditionsReport::Result, ProductViewsToPurchasesReport::Result, TimedResult, Spree::ReturnedProductsReport::Result, TrendingSearchReport::Result, UniquePurchasesReport::Result, UsersNotConvertedReport::Result, UsersWhoRecentlyPurchasedReport::Result
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize {|_self| ... } ⇒ Result
Returns a new instance of Result.
7
8
9
10
|
# File 'app/reports/spree/report/result.rb', line 7
def initialize
yield self
build_report_observations
end
|
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
4
5
6
|
# File 'app/reports/spree/report/result.rb', line 4
def end_date
@end_date
end
|
#observations ⇒ Object
Returns the value of attribute observations.
5
6
7
|
# File 'app/reports/spree/report/result.rb', line 5
def observations
@observations
end
|
#report ⇒ Object
Returns the value of attribute report.
4
5
6
|
# File 'app/reports/spree/report/result.rb', line 4
def report
@report
end
|
#start_date ⇒ Object
Returns the value of attribute start_date.
4
5
6
|
# File 'app/reports/spree/report/result.rb', line 4
def start_date
@start_date
end
|
#time_scale ⇒ Object
Returns the value of attribute time_scale.
4
5
6
|
# File 'app/reports/spree/report/result.rb', line 4
def time_scale
@time_scale
end
|
Class Method Details
.charts(*report_charts) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'app/reports/spree/report/result.rb', line 50
def self.charts(*report_charts)
define_method :chart_json do
{
chart: true,
charts: report_charts.collect { |report_chart| report_chart.new(self).to_h }.flatten
}
end
end
|
Instance Method Details
#build_report_observations ⇒ Object
12
13
14
15
|
# File 'app/reports/spree/report/result.rb', line 12
def build_report_observations
query_results
populate_observations
end
|
#chart_json ⇒ Object
43
44
45
46
47
48
|
# File 'app/reports/spree/report/result.rb', line 43
def chart_json
{
chart: false,
charts: []
}
end
|
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/reports/spree/report/result.rb', line 73
def
report.class::HEADERS.keys.collect do ||
= {
name: Spree.t(.to_sym, scope: [:insight, report.name]),
value: ,
type: report.class::HEADERS[],
sortable: .in?(report.class::SORTABLE_ATTRIBUTES)
}
[:sorted] = report.sort_direction if report.()
end
end
|
#populate_observations ⇒ Object
21
22
23
24
25
26
27
|
# File 'app/reports/spree/report/result.rb', line 21
def populate_observations
@observations = @results.collect do |result|
_observation = self.class::Observation.new
_observation.populate(result)
_observation
end
end
|
#query_results ⇒ Object
17
18
19
|
# File 'app/reports/spree/report/result.rb', line 17
def query_results
@results = report.get_results
end
|
#search_attributes ⇒ Object
59
60
61
|
# File 'app/reports/spree/report/result.rb', line 59
def search_attributes
report.class::SEARCH_ATTRIBUTES.transform_values { |value| value.to_s.humanize }
end
|
#time_dimension ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/reports/spree/report/result.rb', line 86
def time_dimension
case time_scale
when :hourly
:hour_name
when :daily
:day_name
when :monthly
:month_name
when :yearly
:year
end
end
|
#to_h ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/reports/spree/report/result.rb', line 30
def to_h
{
deeplink: report.deeplink_properties,
total_pages: report.total_pages,
per_page: report.records_per_page,
pagination_required: report.,
headers: ,
search_attributes: search_attributes,
stats: observations.collect(&:to_h),
chart_json: chart_json
}
end
|
#total_pages ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'app/reports/spree/report/result.rb', line 63
def total_pages if report.
total_pages = report.total_records / report.records_per_page
if report.total_records % report.records_per_page == 0
total_pages -= 1
end
total_pages
end
end
|