Sha256: 8abf5a49b7e703fb09b1f0ff5b3dd9b0d7b9f5c340f859e19b41f4868cc91000

Contents?: true

Size: 682 Bytes

Versions: 27

Compression:

Stored size: 682 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)
      node ? node.text : ''
    end

    def collect(ns, tag)
      result = []
      # With namespace
      begin
        @xml.xpath("//#{ns}:#{tag}").each do |det|
          result << yield(det)
        end
      rescue StandardError
        # Without namespace
        @xml.xpath("//#{tag}").each do |det|
          result << yield(det)
        end
      end
      result
    end

    def version_is_310_or_newer?
      @xml.css('infNFe').attr('versao').to_s.to_f >= 3.10
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
br_danfe-0.14.0 lib/br_danfe/xml.rb
br_danfe-0.13.3 lib/br_danfe/xml.rb
br_danfe-0.13.2 lib/br_danfe/xml.rb
br_danfe-0.13.1 lib/br_danfe/xml.rb
br_danfe-0.13.0 lib/br_danfe/xml.rb
br_danfe-0.12.1 lib/br_danfe/xml.rb
br_danfe-0.12.0 lib/br_danfe/xml.rb