Class: Relief::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, options = {}, &block) ⇒ Parser

Returns a new instance of Parser.



11
12
13
# File 'lib/relief/parser.rb', line 11

def initialize(name=nil, options={}, &block)
  @root = Element.new(name, options, &block)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/relief/parser.rb', line 9

def root
  @root
end

Instance Method Details

#parse(document) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
# File 'lib/relief/parser.rb', line 15

def parse(document)
  unless document.is_a?(Nokogiri::XML::NodeSet)
    document = Nokogiri::XML(document.to_s)
  end

  raise ParseError if document.root.nil?

  @root.parse(document)
end