Class: ActiveWarehouse::Dimension::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/active_warehouse/dimension.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject (readonly)

Returns the value of attribute children.



281
282
283
# File 'lib/active_warehouse/dimension.rb', line 281

def children
  @children
end

#levelObject (readonly)

Returns the value of attribute level.



281
282
283
# File 'lib/active_warehouse/dimension.rb', line 281

def level
  @level
end

#parentObject (readonly)

Returns the value of attribute parent.



281
282
283
# File 'lib/active_warehouse/dimension.rb', line 281

def parent
  @parent
end

#valueObject (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

Returns:

  • (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