Class: Chicago::Schema::DimensionReference
- Extended by:
- Forwardable
- Defined in:
- lib/chicago/schema/dimension_reference.rb
Overview
A reference to a dimension - supports the API of Column and of Dimension, so you can treat it as either.
Instance Attribute Summary
Attributes inherited from Column
#calculation, #column_type, #default, #elements, #max, #min
Attributes included from NamedElement
Instance Method Summary collapse
- #countable_label ⇒ Object
-
#database_name ⇒ Object
Returns the key name of this dimension.
-
#default_value ⇒ Object
Returns the first null record id for this dimension, or 0 if the dimension has no null records defined.
-
#initialize(name, dimension, opts = {}) ⇒ DimensionReference
constructor
A new instance of DimensionReference.
- #kind_of?(klass) ⇒ Boolean
- #qualify(col) ⇒ Object
- #qualify_by(table) ⇒ Object
-
#roleplayed? ⇒ Boolean
Returns true if this dimension reference is roleplayed - i.e.
- #to_hash ⇒ Object
-
#visit(visitor) ⇒ Object
Dimension references are visitable.
Methods inherited from Column
#==, #binary?, #calculated?, #countable?, #descriptive?, #hash, #indexed?, #internal?, #null?, #numeric?, #optional?, #textual?, #unique?
Constructor Details
#initialize(name, dimension, opts = {}) ⇒ DimensionReference
Returns a new instance of DimensionReference.
13 14 15 16 17 18 |
# File 'lib/chicago/schema/dimension_reference.rb', line 13 def initialize(name, dimension, opts={}) super name, :integer, opts.merge(:min => 0) @dimension = dimension @table_name = "dimension_#{@name}".to_sym @key_name = opts[:key_name] || "#{@name}_dimension_id".to_sym end |
Instance Method Details
#countable_label ⇒ Object
20 21 22 |
# File 'lib/chicago/schema/dimension_reference.rb', line 20 def countable_label "No. of #{label.pluralize}" end |
#database_name ⇒ Object
Returns the key name of this dimension.
25 26 27 |
# File 'lib/chicago/schema/dimension_reference.rb', line 25 def database_name @key_name end |
#default_value ⇒ Object
Returns the first null record id for this dimension, or 0 if the dimension has no null records defined.
53 54 55 56 57 58 59 60 |
# File 'lib/chicago/schema/dimension_reference.rb', line 53 def default_value record = @dimension.null_records.first if record && record[:id] record[:id] else super end end |
#kind_of?(klass) ⇒ Boolean
63 64 65 |
# File 'lib/chicago/schema/dimension_reference.rb', line 63 def kind_of?(klass) klass == Chicago::Schema::Dimension || super end |
#qualify(col) ⇒ Object
35 36 37 |
# File 'lib/chicago/schema/dimension_reference.rb', line 35 def qualify(col) col.qualify_by(@table_name) end |
#qualify_by(table) ⇒ Object
39 40 41 |
# File 'lib/chicago/schema/dimension_reference.rb', line 39 def qualify_by(table) database_name.qualify(table) end |
#roleplayed? ⇒ Boolean
Returns true if this dimension reference is roleplayed - i.e. it has a different name from the underlying dimension so that, for example, multiple date dimensions can be assigned to the same fact table.
47 48 49 |
# File 'lib/chicago/schema/dimension_reference.rb', line 47 def roleplayed? name != @dimension.name end |
#to_hash ⇒ Object
29 30 31 32 33 |
# File 'lib/chicago/schema/dimension_reference.rb', line 29 def to_hash hsh = super hsh[:name] = database_name hsh end |
#visit(visitor) ⇒ Object
Dimension references are visitable
68 69 70 |
# File 'lib/chicago/schema/dimension_reference.rb', line 68 def visit(visitor) visitor.visit_dimension_reference(self) end |