Sha256: 3596bc1f2c841e1064b327acb9796e287a0805175a154890b45c2c11b165b4cb

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 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),
          pICMSST: Helper.numerify(@det.css('ICMS/*/pICMSST').text),
          vBCST: Helper.numerify(@det.css('ICMS/*/vBCST').text),
          vICMSST: Helper.numerify(@det.css('ICMS/*/vICMSST').text))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
br_danfe-0.7.5 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.7.4 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.7.3 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.7.2 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.7.1 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.7.0 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.6.1 lib/br_danfe/danfe_lib/xprod.rb
br_danfe-0.6.0 lib/br_danfe/danfe_lib/xprod.rb