Class: ActiveWarehouse::AggregateField
- Defined in:
- lib/active_warehouse/aggregate_field.rb
Overview
Encapsulates a fact column in a fact table. These fields represent columns that should be aggregated.
Instance Attribute Summary collapse
-
#strategy_name ⇒ Object
readonly
Returns the value of attribute strategy_name.
Attributes inherited from Field
#field_options, #limit, #name, #owning_class, #precision, #scale, #type
Instance Method Summary collapse
-
#fact_class ⇒ Object
delegates to owning_class, returns the Fact that has this field.
-
#initialize(fact_class, column_definition, strategy_name = :sum, field_options = {}) ⇒ AggregateField
constructor
fact_class
is the class of the fact table this field is found in. - #is_semiadditive? ⇒ Boolean
-
#label ⇒ Object
overrides Field.label, prepending the aggregation strategy name to label.
- #levels_from_parent ⇒ Object
-
#semiadditive_over ⇒ Object
returns the Dimension that this semiadditive fact is over.
- #type_cast(value) ⇒ Object
Methods inherited from Field
#column_type, #from_table_name, #label_for_table, #table_alias, #to_s
Constructor Details
#initialize(fact_class, column_definition, strategy_name = :sum, field_options = {}) ⇒ AggregateField
fact_class
is the class of the fact table this field is found in. column_definition
is the ActiveRecord ColumnDefinition instance for this column. strategy_name
is the name of th aggregation strategy to be used, defaults to :sum field_options
is a hash of raw options from the original aggregate definition.
13 14 15 16 17 18 19 20 |
# File 'lib/active_warehouse/aggregate_field.rb', line 13 def initialize(fact_class, column_definition, strategy_name = :sum, = {}) super(fact_class, column_definition.name, column_definition.type, ) @column_definition = column_definition @limit = column_definition.limit @scale = column_definition.scale @precision = column_definition.precision @strategy_name = strategy_name end |
Instance Attribute Details
#strategy_name ⇒ Object (readonly)
Returns the value of attribute strategy_name.
6 7 8 |
# File 'lib/active_warehouse/aggregate_field.rb', line 6 def strategy_name @strategy_name end |
Instance Method Details
#fact_class ⇒ Object
delegates to owning_class, returns the Fact that has this field
23 24 25 |
# File 'lib/active_warehouse/aggregate_field.rb', line 23 def fact_class owning_class end |
#is_semiadditive? ⇒ Boolean
27 28 29 |
# File 'lib/active_warehouse/aggregate_field.rb', line 27 def is_semiadditive? ![:semiadditive].nil? end |
#label ⇒ Object
overrides Field.label, prepending the aggregation strategy name to label
37 38 39 |
# File 'lib/active_warehouse/aggregate_field.rb', line 37 def label @label ? @label : "#{super}_#{strategy_name}" end |
#levels_from_parent ⇒ Object
41 42 43 |
# File 'lib/active_warehouse/aggregate_field.rb', line 41 def levels_from_parent [:levels_from_parent].nil? ? [] : [:levels_from_parent] end |
#semiadditive_over ⇒ Object
returns the Dimension that this semiadditive fact is over
32 33 34 |
# File 'lib/active_warehouse/aggregate_field.rb', line 32 def semiadditive_over Dimension.to_dimension([:semiadditive]) end |
#type_cast(value) ⇒ Object
45 46 47 |
# File 'lib/active_warehouse/aggregate_field.rb', line 45 def type_cast(value) @column_definition.type_cast(value) end |