Class: Kwaff::Element

Inherits:
Node
  • Object
show all
Defined in:
lib/kwaff/node.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#empty_lines

Instance Method Summary collapse

Methods inherited from Node

#to_rexml, #to_xml

Constructor Details

#initialize(tag, children = [], attrs = OrderedHash.new) ⇒ Element

Returns a new instance of Element.



38
39
40
41
42
# File 'lib/kwaff/node.rb', line 38

def initialize(tag, children=[], attrs=OrderedHash.new)
   @tag = tag
   @children = children
   @attrs = attrs		## Hash or OrderedHash
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



43
44
45
# File 'lib/kwaff/node.rb', line 43

def attrs
  @attrs
end

#childrenObject (readonly)

Returns the value of attribute children.



43
44
45
# File 'lib/kwaff/node.rb', line 43

def children
  @children
end

#tagObject

Returns the value of attribute tag.



44
45
46
# File 'lib/kwaff/node.rb', line 44

def tag
  @tag
end

Instance Method Details

#accept(translator, level = 0) ⇒ Object



35
36
37
# File 'lib/kwaff/node.rb', line 35

def accept(translator, level=0)
   return translator.translate_element(self, level)
end

#textObject



46
47
48
49
50
51
52
# File 'lib/kwaff/node.rb', line 46

def text
   if @children.length > 0 && @children[0].is_a?(Text)
      text = children[0]
      return text.str
   end
   return nil
end

#text=(str, flag_escape = true) ⇒ Object



54
55
56
# File 'lib/kwaff/node.rb', line 54

def text=(str, flag_escape=true)
   children[0] = Text.new(str, flag_escape)
end