Class: Tongo::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



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

def initialize(options = {})
  @ns = options[:ns] || 'tng'
end

Instance Attribute Details

#nsObject (readonly)

Returns the value of attribute ns.



3
4
5
# File 'lib/tongo/parser.rb', line 3

def ns
  @ns
end

Instance Method Details

#call(src) ⇒ Object



5
6
7
8
9
# File 'lib/tongo/parser.rb', line 5

def call(src)
  src = "<root xmlns:#{@ns}=\"http://blog.codecaster.es\">#{src}</root>"
  doc = Nokogiri::XML::DocumentFragment.parse(src)
  traverse_children(doc.children)
end