Class: XMLCodec::XMLSOParserElement
- Inherits:
-
Object
- Object
- XMLCodec::XMLSOParserElement
- Defined in:
- lib/stream_object_parser.rb
Overview
This class is used internally by the parser to store the information about each of the elements that gets created.
Instance Attribute Summary collapse
-
#consumed ⇒ Object
readonly
Returns the value of attribute consumed.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#elclass ⇒ Object
readonly
Returns the value of attribute elclass.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Add a child element to the object.
-
#consume ⇒ Object
Consume the object so that it may be freed.
-
#get_object ⇒ Object
Get the actual object for the XML element, created using the elclass passed to the constructor.
-
#initialize(name, attrs, elclass, parent, id, depth) ⇒ XMLSOParserElement
constructor
Create a new instance with the element name, a hash of atributes, it’s import/export class, the parent element and it’s id The id is used to fill in element_id and parent_id in XMLElement so that the parser’s user can know what is the tree structure between objects.
Constructor Details
#initialize(name, attrs, elclass, parent, id, depth) ⇒ XMLSOParserElement
Create a new instance with the element name, a hash of atributes, it’s import/export class, the parent element and it’s id The id is used to fill in element_id and parent_id in XMLElement so that the parser’s user can know what is the tree structure between objects.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stream_object_parser.rb', line 13 def initialize(name, attrs, elclass, parent, id, depth) @attrs = attrs @elclass = elclass @children = Hash.new([]) @children = [] @object = nil @consumed = false @parent = parent @id = id @name = name @depth = depth end |
Instance Attribute Details
#consumed ⇒ Object (readonly)
Returns the value of attribute consumed.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def consumed @consumed end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def depth @depth end |
#elclass ⇒ Object (readonly)
Returns the value of attribute elclass.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def elclass @elclass end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/stream_object_parser.rb', line 7 def parent @parent end |
Instance Method Details
#add_child(child) ⇒ Object
Add a child element to the object
27 28 29 |
# File 'lib/stream_object_parser.rb', line 27 def add_child(child) @children << child end |
#consume ⇒ Object
Consume the object so that it may be freed. The object will no longer appear a a child of the parent object.
48 49 50 51 |
# File 'lib/stream_object_parser.rb', line 48 def consume @consumed = true @object = nil end |
#get_object ⇒ Object
Get the actual object for the XML element, created using the elclass passed to the constructor. This is cached so the object will only be created once. All subsequent calls will return the same object.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stream_object_parser.rb', line 34 def get_object return nil if not @elclass if not @object @object = @elclass.new_with_content(@attrs, @children) if @parent @object.element_id = @id @object.parent_id = @parent.id end end @object end |