Class: CaRuby::ControlledValue

Inherits:
Object
  • Object
show all
Defined in:
lib/caruby/helpers/controlled_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, parent = nil) ⇒ ControlledValue

Creates a new ControlledValue with the given String value and ControlledValue parent. If parent is not nil, then the new CV is added to the parent’s children.



11
12
13
14
15
# File 'lib/caruby/helpers/controlled_value.rb', line 11

def initialize(value=nil, parent=nil)
  @value = value
  self.parent = parent
  @children = Set.new
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/caruby/helpers/controlled_value.rb', line 7

def children
  @children
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/caruby/helpers/controlled_value.rb', line 5

def parent
  @parent
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/caruby/helpers/controlled_value.rb', line 5

def value
  @value
end

Instance Method Details

#descendantsObject



17
18
19
# File 'lib/caruby/helpers/controlled_value.rb', line 17

def descendants
  children + children.map { |child| child.descendants.to_a }.flatten
end

#to_sObject



21
22
23
# File 'lib/caruby/helpers/controlled_value.rb', line 21

def to_s
  value
end