Sha256: 741b27d66d4a07ab0adb5e35b1edf4309995b642a54443f2272d77818e05b805

Contents?: true

Size: 696 Bytes

Versions: 6

Compression:

Stored size: 696 Bytes

Contents

module BrDanfe
  class XML
    def css(xpath)
      @xml.css(xpath)
    end

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

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

    def collect(ns, tag, &block)
      result = []
      # Tenta primeiro com uso de namespace
      begin
        @xml.xpath("//#{ns}:#{tag}").each do |det|
          result << yield(det)
        end
      rescue
        # Caso dĂȘ erro, tenta sem
        @xml.xpath("//#{tag}").each do |det|
          result << yield(det)
        end
      end
      result
    end

    def version_310?
      @xml.css("infNFe").attr("versao").to_s == "3.10"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
br_danfe-0.0.9 lib/br_danfe/xml.rb
br_danfe-0.0.8 lib/br_danfe/xml.rb
br_danfe-0.0.7 lib/br_danfe/xml.rb
br_danfe-0.0.6 lib/br_danfe/xml.rb
br_danfe-0.0.5 lib/br_danfe/xml.rb
br_danfe-0.0.4 lib/br_danfe/xml.rb