Sha256: bff155be323a8d8a703e6b1d61583ba750f2dce9dec1bcf04658c5b6a941d4cf

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

module BrDanfe
  BLACK_COLOR = '000000'.freeze
  GRAY_COLOR = 'A0A0A0'.freeze
  LIGHT_GRAY_COLOR = 'ECECEC'.freeze

  class Mdfe
    attr_reader :logo_options

    def initialize(xml)
      @xml = BrDanfe::XML.new(xml)
      @pdf = MdfeLib::Document.new
      @logo_options = BrDanfe::Logo::Config.new
    end

    def save_pdf(filename)
      generate
      @pdf.render_file(filename)
    end

    def render_pdf
      generate
      @pdf.render
    end

    private

    def generate
      generate_on_first_page
      generate_on_each_page
    end

    def generate_on_first_page
      MdfeLib::Totalizer.new(@pdf, @xml).generate
      MdfeLib::AuthorizationProtocol.new(@pdf, @xml).generate
      MdfeLib::FiscoControl.new(@pdf, @xml).generate
      MdfeLib::Vehicles.new(@pdf, @xml).generate
      MdfeLib::Drivers.new(@pdf, @xml).generate
      MdfeLib::Notes.new(@pdf, @xml).generate
    end

    def generate_on_each_page
      header = MdfeLib::Header.new(@pdf, @xml, @logo_options.logo, @logo_options.logo_dimensions)
      mdfe_identification = MdfeLib::MdfeIdentification.new(@pdf, @xml)

      @pdf.page_count.times do |i|
        page = i + 1

        @pdf.go_to_page page

        header.generate
        mdfe_identification.generate(page)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
br_danfe-1.2.2 lib/br_danfe/mdfe.rb
br_danfe-1.2.1 lib/br_danfe/mdfe.rb
br_danfe-1.2.0 lib/br_danfe/mdfe.rb
br_danfe-1.1.0 lib/br_danfe/mdfe.rb
br_danfe-1.0.0 lib/br_danfe/mdfe.rb
br_danfe-0.20.0 lib/br_danfe/mdfe.rb
br_danfe-0.19.0 lib/br_danfe/mdfe.rb
br_danfe-0.18.0 lib/br_danfe/mdfe.rb
br_danfe-0.17.8 lib/br_danfe/mdfe.rb
br_danfe-0.17.7 lib/br_danfe/mdfe.rb
br_danfe-0.17.6 lib/br_danfe/mdfe.rb
br_danfe-0.17.5 lib/br_danfe/mdfe.rb
br_danfe-0.17.4 lib/br_danfe/mdfe.rb
br_danfe-0.17.3 lib/br_danfe/mdfe.rb
br_danfe-0.17.2 lib/br_danfe/mdfe.rb
br_danfe-0.17.1 lib/br_danfe/mdfe.rb