Class: RubyDanfe::XML

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

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ XML

Returns a new instance of XML.



25
26
27
# File 'lib/ruby_danfe.rb', line 25

def initialize(xml)
  @xml = Nokogiri::XML(xml)
end

Instance Method Details

#[](xpath) ⇒ Object



28
29
30
31
# File 'lib/ruby_danfe.rb', line 28

def [](xpath)
  node = @xml.css(xpath)
  return node ? node.text : ''
end

#collect(xpath, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ruby_danfe.rb', line 35

def collect(xpath, &block)
  result = []
  @xml.xpath(xpath).each do |det|
    result << yield(det)
  end
  result
end

#renderObject



32
33
34
# File 'lib/ruby_danfe.rb', line 32

def render
  RubyDanfe.render @xml.to_s
end