Class: OlapReport::Cube::Measure
- Inherits:
-
Object
- Object
- OlapReport::Cube::Measure
- Defined in:
- lib/olap_report/cube/measure.rb
Defined Under Namespace
Constant Summary collapse
- ALLOWED_FUNCTIONS =
[:avg, :sum, :count]
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #build_relation(relation) ⇒ Object
- #column_type ⇒ Object
-
#initialize(model, name, function = :sum, options = {}) ⇒ Measure
constructor
A new instance of Measure.
Constructor Details
#initialize(model, name, function = :sum, options = {}) ⇒ Measure
Returns a new instance of Measure.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/olap_report/cube/measure.rb', line 9 def initialize(model, name, function=:sum, ={}) raise ArgumentError unless model && name if !ALLOWED_FUNCTIONS.include?(function) && !function.is_a?(Proc) raise OlapReport::Cube::ProhibitedFunctionError, "Function :#{function} is not allowed to use!" end @model = model @name, @function = name, function @column = [:column] || name measures_scope.define_singleton_method name do Statement.new(column_sql) end end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
3 4 5 |
# File 'lib/olap_report/cube/measure.rb', line 3 def column @column end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
3 4 5 |
# File 'lib/olap_report/cube/measure.rb', line 3 def function @function end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/olap_report/cube/measure.rb', line 3 def name @name end |
Instance Method Details
#build_relation(relation) ⇒ Object
25 26 27 |
# File 'lib/olap_report/cube/measure.rb', line 25 def build_relation(relation) relation.select column_with_alias(column_sql, name) end |
#column_type ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/olap_report/cube/measure.rb', line 29 def column_type # @TODO: does this needs refactoring? case function when :count :integer when :avg :float else #model.columns.find{|col| col.name.to_sym == column}.type nil end end |