Class: RubyDanfe::XML
- Inherits:
-
Object
- Object
- RubyDanfe::XML
- Defined in:
- lib/ruby_danfe.rb
Instance Method Summary collapse
- #[](xpath) ⇒ Object
- #collect(xpath, &block) ⇒ Object
-
#initialize(xml) ⇒ XML
constructor
A new instance of XML.
- #render ⇒ Object
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 |