Sha256: bf54fdd8eeea6fb9514702c61ce2e44bd605500856fa14240678f62576c107ae

Contents?: true

Size: 795 Bytes

Versions: 11

Compression:

Stored size: 795 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)
        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_is_310_or_newer?
        @xml.css("infNFe").attr("versao").to_s.to_f >= 3.10
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
br_danfe-0.11.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.11.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.10.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.10.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.8.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.7 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.6 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.5 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.4 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.3 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.2 lib/br_danfe/danfe_lib/xml.rb