Class: XmlParsable::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlparsable/parser.rb

Defined Under Namespace

Modules: StubElement

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#documentsObject (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_documentObject



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_documentObject



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