Class: Saulabs::Reportable::Report
- Inherits:
-
Object
- Object
- Saulabs::Reportable::Report
- Defined in:
- lib/saulabs/reportable/report.rb
Overview
The Report class that does all the data retrieval and calculations.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#aggregation ⇒ Object
readonly
the aggregation to use (one of
:count
,:sum
,:minimum
,:maximum
or:average
); when using anything other than:count
,:value_column
must also be specified. -
#date_column ⇒ Object
readonly
the name of the date column over that the records are aggregated.
-
#klass ⇒ Object
readonly
the model the report works on (This is the class you invoke ClassMethods#reportable on).
-
#name ⇒ Object
readonly
the name of the report (as in ClassMethods#reportable).
-
#options ⇒ Object
readonly
options for the report.
-
#value_column ⇒ Object
readonly
the name of the column that holds the values to aggregate when using a calculation aggregation like
:sum
.
Instance Method Summary collapse
-
#initialize(klass, name, options = {}) ⇒ Report
constructor
Initializes a new Report.
-
#run(options = {}) ⇒ Array<Array<DateTime, Float>>
Runs the report and returns an array of array of DateTimes and Floats.
Constructor Details
#initialize(klass, name, options = {}) ⇒ Report
Initializes a new Saulabs::Reportable::Report
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/saulabs/reportable/report.rb', line 64 def initialize(klass, name, = {}) () @klass = klass @name = name @date_column = ([:date_column] || 'created_at').to_s @aggregation = [:aggregation] || :count @value_column = ([:value_column] || (@aggregation == :count ? 'id' : name)).to_s @options = { :limit => [:limit] || 100, :distinct => [:distinct] || false, :include => [:include] || [], :conditions => [:conditions] || [], :grouping => Grouping.new([:grouping] || :day), :live_data => [:live_data] || false, :end_date => [:end_date] || false } @options.merge!() @options.freeze end |
Instance Attribute Details
#aggregation ⇒ Object (readonly)
the aggregation to use (one of :count
, :sum
, :minimum
, :maximum
or :average
); when using anything other than :count
, :value_column
must also be specified
30 31 32 |
# File 'lib/saulabs/reportable/report.rb', line 30 def aggregation @aggregation end |
#date_column ⇒ Object (readonly)
the name of the date column over that the records are aggregated
22 23 24 |
# File 'lib/saulabs/reportable/report.rb', line 22 def date_column @date_column end |
#klass ⇒ Object (readonly)
the model the report works on (This is the class you invoke ClassMethods#reportable on)
14 15 16 |
# File 'lib/saulabs/reportable/report.rb', line 14 def klass @klass end |
#name ⇒ Object (readonly)
the name of the report (as in ClassMethods#reportable)
18 19 20 |
# File 'lib/saulabs/reportable/report.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
options for the report
34 35 36 |
# File 'lib/saulabs/reportable/report.rb', line 34 def @options end |
#value_column ⇒ Object (readonly)
the name of the column that holds the values to aggregate when using a calculation aggregation like :sum
26 27 28 |
# File 'lib/saulabs/reportable/report.rb', line 26 def value_column @value_column end |
Instance Method Details
#run(options = {}) ⇒ Array<Array<DateTime, Float>>
Runs the report and returns an array of array of DateTimes and Floats
103 104 105 106 107 108 |
# File 'lib/saulabs/reportable/report.rb', line 103 def run( = {}) = () ReportCache.process(self, ) do |begin_at, end_at| read_data(begin_at, end_at, ) end end |