Class: ActiveWarehouse::Dimension::Node
- Inherits:
-
Object
- Object
- ActiveWarehouse::Dimension::Node
- Defined in:
- lib/active_warehouse/dimension.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add_child(child_value, level) ⇒ Object
- #child(child_value) ⇒ Object
- #has_child?(child_value) ⇒ Boolean
-
#initialize(value, level, parent = nil) ⇒ Node
constructor
A new instance of Node.
- #optionally_add_child(child_value, level) ⇒ Object
Constructor Details
#initialize(value, level, parent = nil) ⇒ Node
Returns a new instance of Node.
283 284 285 286 287 288 |
# File 'lib/active_warehouse/dimension.rb', line 283 def initialize(value, level, parent = nil) @children = [] @value = value @parent = parent @level = level end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
281 282 283 |
# File 'lib/active_warehouse/dimension.rb', line 281 def children @children end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
281 282 283 |
# File 'lib/active_warehouse/dimension.rb', line 281 def level @level end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
281 282 283 |
# File 'lib/active_warehouse/dimension.rb', line 281 def parent @parent end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
281 282 283 |
# File 'lib/active_warehouse/dimension.rb', line 281 def value @value end |
Instance Method Details
#add_child(child_value, level) ⇒ Object
301 302 303 304 305 |
# File 'lib/active_warehouse/dimension.rb', line 301 def add_child(child_value, level) child = Node.new(child_value, level, self) @children << child child end |
#child(child_value) ⇒ Object
294 295 296 297 298 299 |
# File 'lib/active_warehouse/dimension.rb', line 294 def child(child_value) @children.each do |c| return c if c.value == child_value end nil end |
#has_child?(child_value) ⇒ Boolean
290 291 292 |
# File 'lib/active_warehouse/dimension.rb', line 290 def has_child?(child_value) !self.child(child_value).nil? end |
#optionally_add_child(child_value, level) ⇒ Object
307 308 309 310 311 |
# File 'lib/active_warehouse/dimension.rb', line 307 def optionally_add_child(child_value, level) c = child(child_value) c = add_child(child_value, level) unless c c end |