Sha256: 0a185b1920a11334a39bcec4a7364a056c561473524d29750d60cc64acb83a9b

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 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 = 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

2 entries across 2 versions & 1 rubygems

Version Path
br_danfe-0.17.0 lib/br_danfe/mdfe.rb
br_danfe-0.16.0 lib/br_danfe/mdfe.rb