Module: RD::NonterminalElement

Included in:
DescListItem::Term, DocumentElement, Headline, List, ListItem, NonterminalInline, TextBlock
Defined in:
lib/rd/element.rb

Overview

element which have children.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#temporary_document_structureObject

Returns the value of attribute temporary_document_structure.



99
100
101
# File 'lib/rd/element.rb', line 99

def temporary_document_structure
  @temporary_document_structure
end

Instance Method Details

#add_child(child) ⇒ Object



62
63
64
# 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) ⇒ Object



66
67
68
69
70
71
72
73
74
# 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) ⇒ Object



76
77
78
# 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) ⇒ Object



80
81
82
83
84
85
# 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) ⇒ Object



87
88
89
90
91
92
# 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) ⇒ Object



101
102
103
104
105
106
# 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

#childrenObject

Raises:

  • (NotImplimentedError)


44
45
46
# File 'lib/rd/element.rb', line 44

def children
  raise NotImplimentedError, "need #{self}#children."
end

#each_childObject



48
49
50
51
52
# File 'lib/rd/element.rb', line 48

def each_child
  children.each do |i|
	yield(i)
  end
end

#each_element {|_self| ... } ⇒ Object Also known as: each

Yields:

  • (_self)

Yield Parameters:



54
55
56
57
58
59
# File 'lib/rd/element.rb', line 54

def each_element(&block)
  yield(self)
  children.each do |i|
	i.each_element(&block)
  end
end

#initialize(*arg) ⇒ Object



39
40
41
42
# File 'lib/rd/element.rb', line 39

def initialize(*arg)
  @temporary_document_structure = nil
  super
end

#make_child(child_class, *args_of_new, &block) ⇒ Object Also known as: new



108
109
110
111
112
113
114
115
116
117
118
119
# 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

#push_to_children(child) ⇒ Object



94
95
96
97
# 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) ⇒ Object

NonterminalElement#new, not NonterminalElement.new



124
125
126
127
128
129
130
131
# 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