Class: ActiveWarehouse::AggregateField

Inherits:
Field
  • Object
show all
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

Attributes inherited from Field

#field_options, #limit, #name, #owning_class, #precision, #scale, #type

Instance Method Summary collapse

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, field_options = {})
  super(fact_class, column_definition.name, column_definition.type, field_options)
  @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_nameObject (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_classObject

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/active_warehouse/aggregate_field.rb', line 27

def is_semiadditive?
  !field_options[:semiadditive].nil?
end

#labelObject

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_parentObject



41
42
43
# File 'lib/active_warehouse/aggregate_field.rb', line 41

def levels_from_parent
  field_options[:levels_from_parent].nil? ? [] : field_options[:levels_from_parent]
end

#semiadditive_overObject

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(field_options[: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