Class: OlapReport::Cube::Dimension
- Inherits:
-
Object
- Object
- OlapReport::Cube::Dimension
- Defined in:
- lib/olap_report/cube/dimension.rb
Instance Attribute Summary collapse
-
#levels ⇒ Object
readonly
Returns the value of attribute levels.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#[](level_name) ⇒ OlapReport::Cube::Level
Finds level by name from dimension.
-
#dates(field, options = {}) ⇒ Object
Defines date-based levels for dimension.
-
#initialize(model, name) ⇒ Dimension
constructor
A new instance of Dimension.
-
#level(name, options = {}) ⇒ Object
Defines level for dimension.
- #level_index(level_name) ⇒ Object
- #next_level(level_name) ⇒ Object
- #prev_level(level_name) ⇒ Object
Constructor Details
#initialize(model, name) ⇒ Dimension
Returns a new instance of Dimension.
5 6 7 8 9 10 |
# File 'lib/olap_report/cube/dimension.rb', line 5 def initialize(model, name) raise ArgumentError unless model && name @levels = [] @name = name @model = model end |
Instance Attribute Details
#levels ⇒ Object (readonly)
Returns the value of attribute levels.
3 4 5 |
# File 'lib/olap_report/cube/dimension.rb', line 3 def levels @levels end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/olap_report/cube/dimension.rb', line 3 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/olap_report/cube/dimension.rb', line 3 def name @name end |
Instance Method Details
#[](level_name) ⇒ OlapReport::Cube::Level
Finds level by name from dimension
34 35 36 |
# File 'lib/olap_report/cube/dimension.rb', line 34 def [](level_name) levels.find{|l| l.name == level_name} || raise(KeyError, "Level '#{level_name}' not found for dimension '#{self.name}'") end |
#dates(field, options = {}) ⇒ Object
Defines date-based levels for dimension
22 23 24 25 26 27 28 29 |
# File 'lib/olap_report/cube/dimension.rb', line 22 def dates(field, = {}) levels = [:by] if levels.present? levels.each{ |name| level name, column: field, type: name } else level field end end |
#level(name, options = {}) ⇒ Object
Defines level for dimension
15 16 17 |
# File 'lib/olap_report/cube/dimension.rb', line 15 def level(name, = {}) @levels << Cube::Level.new(self, name, ) end |
#level_index(level_name) ⇒ Object
38 39 40 |
# File 'lib/olap_report/cube/dimension.rb', line 38 def level_index(level_name) levels.map(&:name).index(level_name) end |
#next_level(level_name) ⇒ Object
46 47 48 |
# File 'lib/olap_report/cube/dimension.rb', line 46 def next_level(level_name) levels[level_index(level_name) + 1] end |
#prev_level(level_name) ⇒ Object
42 43 44 |
# File 'lib/olap_report/cube/dimension.rb', line 42 def prev_level(level_name) levels[level_index(level_name) - 1] end |