Class: XmlParsable::Parser
- Inherits:
-
Object
- Object
- XmlParsable::Parser
- Defined in:
- lib/xmlparsable/parser.rb
Defined Under Namespace
Modules: StubElement
Instance Attribute Summary collapse
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Instance Method Summary collapse
-
#initialize(constructed = nil, &constructor) ⇒ Parser
constructor
A new instance of Parser.
- #on_cdata_block(text) ⇒ Object
- #on_characters(text) ⇒ Object
- #on_comment(comment) ⇒ Object
- #on_end_document ⇒ Object
- #on_end_element_ns(name, prefix, uri) ⇒ Object
- #on_processing_instruction(name, attributes) ⇒ Object
- #on_start_document ⇒ Object
- #on_start_element_ns(name, attributes, prefix, uri, namespaces) ⇒ Object
Constructor Details
#initialize(constructed = nil, &constructor) ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 |
# File 'lib/xmlparsable/parser.rb', line 5 def initialize(constructed = nil, &constructor) @documents = Array.new @constructor = constructor || lambda { constructed } end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
3 4 5 |
# File 'lib/xmlparsable/parser.rb', line 3 def documents @documents end |
Instance Method Details
#on_cdata_block(text) ⇒ Object
26 27 28 |
# File 'lib/xmlparsable/parser.rb', line 26 def on_cdata_block(text) @stack.first.read(text) end |
#on_characters(text) ⇒ Object
22 23 24 |
# File 'lib/xmlparsable/parser.rb', line 22 def on_characters(text) @stack.first.read(text) end |
#on_comment(comment) ⇒ Object
30 31 32 |
# File 'lib/xmlparsable/parser.rb', line 30 def on_comment(comment) @stack.first.comment(comment) end |
#on_end_document ⇒ Object
18 19 20 |
# File 'lib/xmlparsable/parser.rb', line 18 def on_end_document @documents << @stack.shift.finalize end |
#on_end_element_ns(name, prefix, uri) ⇒ Object
38 39 40 |
# File 'lib/xmlparsable/parser.rb', line 38 def on_end_element_ns(name, prefix, uri) @stack.shift.finalize end |
#on_processing_instruction(name, attributes) ⇒ Object
10 11 12 |
# File 'lib/xmlparsable/parser.rb', line 10 def on_processing_instruction(name, attributes) # ignore end |
#on_start_document ⇒ Object
14 15 16 |
# File 'lib/xmlparsable/parser.rb', line 14 def on_start_document @stack = [@constructor.call] end |
#on_start_element_ns(name, attributes, prefix, uri, namespaces) ⇒ Object
34 35 36 |
# File 'lib/xmlparsable/parser.rb', line 34 def on_start_element_ns(name, attributes, prefix, uri, namespaces) @stack.unshift(@stack.first.open(name, attributes) || StubElement) end |