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.
250 251 252 253 254 255 |
# File 'lib/active_warehouse/dimension.rb', line 250 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.
248 249 250 |
# File 'lib/active_warehouse/dimension.rb', line 248 def children @children end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
248 249 250 |
# File 'lib/active_warehouse/dimension.rb', line 248 def level @level end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
248 249 250 |
# File 'lib/active_warehouse/dimension.rb', line 248 def parent @parent end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
248 249 250 |
# File 'lib/active_warehouse/dimension.rb', line 248 def value @value end |
Instance Method Details
#add_child(child_value, level) ⇒ Object
268 269 270 271 272 |
# File 'lib/active_warehouse/dimension.rb', line 268 def add_child(child_value, level) child = Node.new(child_value, level, self) @children << child child end |
#child(child_value) ⇒ Object
261 262 263 264 265 266 |
# File 'lib/active_warehouse/dimension.rb', line 261 def child(child_value) @children.each do |c| return c if c.value == child_value end nil end |
#has_child?(child_value) ⇒ Boolean
257 258 259 |
# File 'lib/active_warehouse/dimension.rb', line 257 def has_child?(child_value) !self.child(child_value).nil? end |
#optionally_add_child(child_value, level) ⇒ Object
274 275 276 277 278 |
# File 'lib/active_warehouse/dimension.rb', line 274 def optionally_add_child(child_value, level) c = child(child_value) c = add_child(child_value, level) unless c c end |