Sha256: c1f983f910b02cd52f5d715b079aa0cf621c573a97dafe006a0e762b4aa762d4

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

module BrDanfe
  module DanfeLib
    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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
br_danfe-0.11.2 lib/br_danfe/danfe_lib/xml.rb