Sha256: 45110cf222a32e28bf6e54a6c6ad9f4c407ec4b8d12002302473c4f52ab653e9

Contents?: true

Size: 780 Bytes

Versions: 16

Compression:

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
br_danfe-0.7.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.7.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.6.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.6.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.5.2 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.5.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.5.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.4.3 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.4.2 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.4.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.4.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.3.0 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.2.3 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.2.2 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.2.1 lib/br_danfe/danfe_lib/xml.rb
br_danfe-0.2.0 lib/br_danfe/danfe_lib/xml.rb