Module: XamplGenerator::ElementAsChild

Included in:
Elements
Defined in:
lib/xamplr/xampl-hand-generated.rb

Instance Method Summary collapse

Instance Method Details

#add_element(element) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/xamplr/xampl-hand-generated.rb', line 103

def add_element(element)
  accessed
  index = element.get_the_index
  if (nil == index) then
    throw "no value for the index 'name' of element defined in : " << element.pp_xml
  end

  existing = @element_child[index]

  self.remove_element(index) if existing and (existing != element)

  @children << element
  @element_child[index] = element

  element.add_parent(self)

  changed
  return element
end

#element_childObject Also known as: element



86
87
88
89
# File 'lib/xamplr/xampl-hand-generated.rb', line 86

def element_child
  accessed
  @element_child
end

#element_child=(v) ⇒ Object Also known as: element=



91
92
93
94
# File 'lib/xamplr/xampl-hand-generated.rb', line 91

def element_child=(v)
  accessed
  @element_child = v
end

#ensure_element(index) {|element| ... } ⇒ Object

Yields:



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/xamplr/xampl-hand-generated.rb', line 133

def ensure_element(index)
  accessed

  element = @element_child[index]
  return element if element

  element = Element.new(index) unless element

  yield(element) if block_given?
  return add_element(element)
end

#init_element_as_childObject



99
100
101
# File 'lib/xamplr/xampl-hand-generated.rb', line 99

def init_element_as_child
  @element_child = IndexedArray.new
end

#new_element(index) {|element| ... } ⇒ Object

Yields:



123
124
125
126
127
128
129
130
131
# File 'lib/xamplr/xampl-hand-generated.rb', line 123

def new_element(index)
  accessed

  element = nil
  element = Element.new(index) unless element

  yield(element) if block_given?
  return add_element(element)
end

#remove_element(index) ⇒ Object



145
146
147
148
149
150
151
152
153
# File 'lib/xamplr/xampl-hand-generated.rb', line 145

def remove_element(index)
  accessed
  changed
  unless String === index or Symbol === index then
    index = index.get_the_index
  end
  element = @element_child.delete(index) if index
  @children.delete(element)
end