Class: XmlParsable::Elements::TextElement

Inherits:
XmlElement::Node show all
Defined in:
lib/xmlparsable/elements/text.rb

Overview

Parses content into a ruby String value. Discards comments and flattens children elements so “abc def what<!– foo –>ever” is read as “abc def whatever”

Defined Under Namespace

Classes: String

Instance Attribute Summary collapse

Attributes inherited from XmlElement::Node

#children, #xmlattr

Instance Method Summary collapse

Methods inherited from XmlElement::Node

#to_s

Methods inherited from AbstractElement

parsable

Constructor Details

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

Returns a new instance of TextElement.



15
16
17
18
# File 'lib/xmlparsable/elements/text.rb', line 15

def initialize(name, attributes, parent, arguments)
  @name, @attributes, @parent, @arguments, @text =
    name, attributes, parent, arguments, String.new
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/xmlparsable/elements/text.rb', line 13

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/xmlparsable/elements/text.rb', line 13

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



13
14
15
# File 'lib/xmlparsable/elements/text.rb', line 13

def parent
  @parent
end

Instance Method Details

#close(element, value) ⇒ Object



31
32
33
# File 'lib/xmlparsable/elements/text.rb', line 31

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

#comment(text) ⇒ Object



28
29
# File 'lib/xmlparsable/elements/text.rb', line 28

def comment(text)
end

#finalizeObject



35
36
37
38
# File 'lib/xmlparsable/elements/text.rb', line 35

def finalize
  @text.instance_variable_set(:@xmlattrs, @attributes)
  @parent.close(self, @text)
end

#open(name, attributes) ⇒ Object



20
21
22
# File 'lib/xmlparsable/elements/text.rb', line 20

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

#read(text) ⇒ Object



24
25
26
# File 'lib/xmlparsable/elements/text.rb', line 24

def read(text)
  @text << text
end