Class: Pivotable::Expression::Calculation
- Defined in:
- lib/pivotable/expression/calculation.rb
Instance Attribute Summary collapse
-
#function ⇒ Object
readonly
Returns the value of attribute function.
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(model, name, options = {}) ⇒ Calculation
constructor
A new instance of Calculation.
- #to_group ⇒ Object
- #to_select ⇒ Object
Constructor Details
#initialize(model, name, options = {}) ⇒ Calculation
Returns a new instance of Calculation.
5 6 7 8 9 10 11 12 13 |
# File 'lib/pivotable/expression/calculation.rb', line 5 def initialize(model, name, = {}) super @function = [:function] if [:function].is_a?(Symbol) if via.is_a?(Arel::Attribute) raise ArgumentError, "No calculation function provided for '#{@name}'. Please provide a :function option" unless function @via = via.send(function) end end |
Instance Attribute Details
#function ⇒ Object (readonly)
Returns the value of attribute function.
3 4 5 |
# File 'lib/pivotable/expression/calculation.rb', line 3 def function @function end |
Instance Method Details
#to_group ⇒ Object
24 25 26 |
# File 'lib/pivotable/expression/calculation.rb', line 24 def to_group raise RuntimeError, "Cannot group by calculation" end |
#to_select ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pivotable/expression/calculation.rb', line 15 def to_select case via when String "#{via} AS #{name}" else via.clone.as(name) end end |