Class: ActiveWarehouse::Field
- Inherits:
-
Object
- Object
- ActiveWarehouse::Field
- Defined in:
- lib/active_warehouse/field.rb
Overview
Encapsulates a field.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field_options ⇒ Object
readonly
A Hash of options for the field.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#name ⇒ Object
readonly
returns name of this field, matches name of the column.
-
#owning_class ⇒ Object
readonly
The owning class which is either a Fact or Dimension.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#type ⇒ Object
readonly
The field type.
Instance Method Summary collapse
-
#column_type ⇒ Object
returns rails specific column type, e.g.
-
#from_table_name ⇒ Object
returns the table name that has this fact column.
-
#initialize(owning_class, name, type, field_options = {}) ⇒ Field
constructor
owning_class
is the class of the table, either Fact or Dimension, that this field is found in. -
#label ⇒ Object
returns the :label set in field_options, or from_table_name+‘_’+name.
-
#label_for_table ⇒ Object
convert the label into something we can use in a table.
-
#table_alias ⇒ Object
returns a table alias or if none set just the table name.
-
#to_s ⇒ Object
Get a display string for the field.
Constructor Details
#initialize(owning_class, name, type, field_options = {}) ⇒ Field
owning_class
is the class of the table, either Fact or Dimension, that this field is found in. Must somehow subclass ActiveRecord::Base name
is the name of this field. field_options
is a hash of raw options from the original definition. Options can include :label => a column alias or label for this field, :table_alias for a table alias (useful for building queries)
26 27 28 29 30 31 32 33 |
# File 'lib/active_warehouse/field.rb', line 26 def initialize(owning_class, name, type, = {}) @owning_class = owning_class @name = name @type = type @field_options = @label = [:label] @table_alias = [:table_alias] end |
Instance Attribute Details
#field_options ⇒ Object (readonly)
A Hash of options for the field
18 19 20 |
# File 'lib/active_warehouse/field.rb', line 18 def @field_options end |
#limit ⇒ Object
Returns the value of attribute limit.
13 14 15 |
# File 'lib/active_warehouse/field.rb', line 13 def limit @limit end |
#name ⇒ Object (readonly)
returns name of this field, matches name of the column
8 9 10 |
# File 'lib/active_warehouse/field.rb', line 8 def name @name end |
#owning_class ⇒ Object (readonly)
The owning class which is either a Fact or Dimension
5 6 7 |
# File 'lib/active_warehouse/field.rb', line 5 def owning_class @owning_class end |
#precision ⇒ Object
Returns the value of attribute precision.
15 16 17 |
# File 'lib/active_warehouse/field.rb', line 15 def precision @precision end |
#scale ⇒ Object
Returns the value of attribute scale.
14 15 16 |
# File 'lib/active_warehouse/field.rb', line 14 def scale @scale end |
#type ⇒ Object (readonly)
The field type
11 12 13 |
# File 'lib/active_warehouse/field.rb', line 11 def type @type end |
Instance Method Details
#column_type ⇒ Object
returns rails specific column type, e.g. :float or :string
48 49 50 |
# File 'lib/active_warehouse/field.rb', line 48 def column_type @type end |
#from_table_name ⇒ Object
returns the table name that has this fact column
59 60 61 |
# File 'lib/active_warehouse/field.rb', line 59 def from_table_name owning_class.table_name end |
#label ⇒ Object
returns the :label set in field_options, or from_table_name+‘_’+name. Unless you have table_alias specified, then label will return table_alias+‘_’+name. The default label can exceed database limits, so use :label to override.
38 39 40 |
# File 'lib/active_warehouse/field.rb', line 38 def label @label ? @label : "#{table_alias || from_table_name}_#{name}" end |
#label_for_table ⇒ Object
convert the label into something we can use in a table. i.e., ‘Sum of Transactions’ becomes ‘sum_of_transactions’
54 55 56 |
# File 'lib/active_warehouse/field.rb', line 54 def label_for_table label.gsub(/ /, '_').downcase end |
#table_alias ⇒ Object
returns a table alias or if none set just the table name
64 65 66 |
# File 'lib/active_warehouse/field.rb', line 64 def table_alias @table_alias || from_table_name end |
#to_s ⇒ Object
Get a display string for the field. Delegates to label.
69 70 71 |
# File 'lib/active_warehouse/field.rb', line 69 def to_s label end |