module RD::NonterminalElement

element which have children.

Attributes

temporary_document_structure[RW]

Public Class Methods

new(*arg) click to toggle source
Calls superclass method
# File lib/rd/element.rb, line 39
def initialize(*arg)
  @temporary_document_structure = nil
  super
end

Public Instance Methods

add_child(child) click to toggle source
# File lib/rd/element.rb, line 62
def add_child(child)
  add_child_under_document_struct(child, tree.document_struct)
end
add_child_under_document_struct(child, document_struct) click to toggle source
# File lib/rd/element.rb, line 66
def add_child_under_document_struct(child, document_struct)
  if document_struct.is_valid?(self, child)
    push_to_children(child)
  else
    raise ArgumentError,
      "mismatched document structure, #{self} <-/- #{child}."
  end
  return self
end
add_children(children) click to toggle source
# File lib/rd/element.rb, line 76
def add_children(children)
  add_children_under_document_struct(children, tree.document_struct)
end
add_children_under_document_struct(children, document_struct) click to toggle source
# File lib/rd/element.rb, line 80
def add_children_under_document_struct(children, document_struct)
  children.each do |i|
    add_child_under_document_struct(i, document_struct)
  end
  return self
end
add_children_without_document_struct(new_children) click to toggle source
# File lib/rd/element.rb, line 87
def add_children_without_document_struct(new_children)
  new_children.each do |i|
    push_to_children(i)
  end
  return self
end
build(document_struct = tree.document_struct, &block) click to toggle source
# File lib/rd/element.rb, line 101
def build(document_struct = tree.document_struct, &block)
  under_temporary_document_structure(document_struct) do
    self.instance_eval(&block)
  end
  self
end
children() click to toggle source
# File lib/rd/element.rb, line 44
def children
  raise NotImplimentedError, "need #{self}#children."
end
each(&block)
Alias for: each_element
each_child() { |i| ... } click to toggle source
# File lib/rd/element.rb, line 48
def each_child
  children.each do |i|
    yield(i)
  end
end
each_element() { |self| ... } click to toggle source
# File lib/rd/element.rb, line 54
def each_element(&block)
  yield(self)
  children.each do |i|
    i.each_element(&block)
  end
end
Also aliased as: each
make_child(child_class, *args_of_new, &block) click to toggle source
# File lib/rd/element.rb, line 108
def make_child(child_class, *args_of_new, &block)
  child = child_class.new(*args_of_new)
  if self.temporary_document_structure
    self.add_child_under_document_struct(child,
                                         self.temporary_document_structure)
    child.build(self.temporary_document_structure, &block) if block_given?
  else
    self.add_child(child)
    child.build(&block) if block_given?
  end
  child
end
Also aliased as: new
push_to_children(child) click to toggle source
# File lib/rd/element.rb, line 94
def push_to_children(child)
  children.push(child)
  child.parent = self
end
under_temporary_document_structure(document_struct) { || ... } click to toggle source

NonterminalElement#new, not NonterminalElement.new

# File lib/rd/element.rb, line 124
def under_temporary_document_structure(document_struct)
  begin
    self.temporary_document_structure = document_struct
    yield
  ensure
    self.temporary_document_structure = nil
  end
end

Private Instance Methods

indent2(str) click to toggle source
# File lib/rd/element.rb, line 133
def indent2(str)
  buf = ''
  str.each_line{|i| buf << "  " << i }
  buf
end
new(child_class, *args_of_new, &block)
Alias for: make_child