Class: XmlParsable::Elements::XmlElement::Node

Inherits:
AbstractElement show all
Defined in:
lib/xmlparsable/elements/xml.rb

Direct Known Subclasses

TextElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

parsable

Constructor Details

#initialize(name, attributes, parent, arguments) ⇒ Node

Returns a new instance of Node.



16
17
18
19
# File 'lib/xmlparsable/elements/xml.rb', line 16

def initialize(name, attributes, parent, arguments)
  @name, @attributes, @parent, @arguments, @children =
    name, attributes, parent, arguments, Array.new
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def parent
  @parent
end

#xmlattrObject (readonly)

Returns the value of attribute xmlattr.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def xmlattr
  @xmlattr
end

Instance Method Details

#close(element, value) ⇒ Object



33
34
35
# File 'lib/xmlparsable/elements/xml.rb', line 33

def close(element, value)
  @children << value
end

#comment(text) ⇒ Object



29
30
31
# File 'lib/xmlparsable/elements/xml.rb', line 29

def comment(text)
  @children << Comment.new(text, self)
end

#finalizeObject



37
38
39
# File 'lib/xmlparsable/elements/xml.rb', line 37

def finalize
  @parent.close(self, self)
end

#open(name, attributes) ⇒ Object



21
22
23
# File 'lib/xmlparsable/elements/xml.rb', line 21

def open(name, attributes)
  Node.new(name, attributes, self, @arguments)
end

#read(text) ⇒ Object



25
26
27
# File 'lib/xmlparsable/elements/xml.rb', line 25

def read(text)
  @children << Text.new(text, self)
end

#to_s(buffer = "") ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xmlparsable/elements/xml.rb', line 41

def to_s(buffer = "")
  buffer << "<#{@name}"
  @attributes.each{|name, value| buffer << %[ #{name}='#{value}'] }

  if @children.empty?
    buffer << "/>"
  else
    buffer << ">"
    @children.each{|child| child.to_s(buffer) }
    buffer << "</#{@name}>" 
  end
end