Sha256: e526b8f48308b09f511d30fee16c16aaf91dbbb57857aab8a6877d9262f2315d

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

module BrDanfe
  module DanfeLib
    class Xprod
      def initialize(det)
        @det = det
      end

      def render
        xprod = "#{@det.css('prod/xProd').text}"

        xprod += infAdProd if has_infAdProd?
        xprod += fci if has_fci?
        xprod += st if has_st?

        xprod
      end

      private
      def has_infAdProd?
        !@det.css("infAdProd").text.empty?
      end

      def has_fci?
        !@det.css("prod/nFCI").text.empty?
      end

      def has_st?
        @det.css("ICMS/*/vBCST").text.to_i > 0
      end

      def infAdProd
        "\n" + @det.css("infAdProd").text
      end

      def fci
        "\n" + I18n.t("danfe.det.prod.xProdFCI", nFCI: @det.css('prod/nFCI').text)
      end

      def st
        "\n" + I18n.t("danfe.det.prod.xProdST",
          pMVAST: Helper.numerify(@det.css('ICMS/*/pMVAST').text, 2),
          pICMSST: Helper.numerify(@det.css('ICMS/*/pICMSST').text, 2),
          vBCST: Helper.numerify(@det.css('ICMS/*/vBCST').text, 2),
          vICMSST: Helper.numerify(@det.css('ICMS/*/vICMSST').text, 2))
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
br_danfe-0.5.2 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.5.1 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.5.0 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.4.3 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.3.0 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.2.3 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.2.2 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.2.1 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.2.0 lib/br_danfe/danfe_lib/xprod.rb