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-1.0.0 lib/br_danfe/xml.rb
br_danfe-0.20.0 lib/br_danfe/xml.rb
br_danfe-0.19.0 lib/br_danfe/xml.rb
br_danfe-0.18.0 lib/br_danfe/xml.rb
br_danfe-0.17.8 lib/br_danfe/xml.rb
br_danfe-0.17.7 lib/br_danfe/xml.rb
br_danfe-0.17.6 lib/br_danfe/xml.rb
br_danfe-0.17.5 lib/br_danfe/xml.rb
br_danfe-0.17.4 lib/br_danfe/xml.rb
br_danfe-0.17.3 lib/br_danfe/xml.rb
br_danfe-0.17.2 lib/br_danfe/xml.rb
br_danfe-0.17.1 lib/br_danfe/xml.rb
br_danfe-0.17.0 lib/br_danfe/xml.rb
br_danfe-0.16.0 lib/br_danfe/xml.rb
br_danfe-0.15.1 lib/br_danfe/xml.rb
br_danfe-0.15.0 lib/br_danfe/xml.rb
br_danfe-0.14.5 lib/br_danfe/xml.rb
br_danfe-0.14.4 lib/br_danfe/xml.rb
br_danfe-0.14.3 lib/br_danfe/xml.rb
br_danfe-0.14.2 lib/br_danfe/xml.rb