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
- #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.
45 46 47 48 49 50 51 52 |
# File 'lib/chicago/schema/dimension_reference.rb', line 45 def default_value record = @dimension.null_records.first if record && record[:id] record[:id] else super end end |
#kind_of?(klass) ⇒ Boolean
55 56 57 |
# File 'lib/chicago/schema/dimension_reference.rb', line 55 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 |
#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
60 61 62 |
# File 'lib/chicago/schema/dimension_reference.rb', line 60 def visit(visitor) visitor.visit_dimension_reference(self) end |