Sha256: 7243c709543d556c2904b0d4add9488e40951d0af5381807aa334c46635cfcfe

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# encoding:utf-8
module RubyDanfe
  def self.generate(pdf_filename, xml_filename, type = :danfe, new_options = {})
    self.options = new_options if !new_options.empty?

    xml_string = File.new(xml_filename)
    render_file(pdf_filename, xml_string, type)
  end

  def self.render(xml_string, type = :danfe, new_options = {})
    self.options = new_options if !new_options.empty?

    pdf = generatePDF(xml_string, type)
    pdf.render
  end

  def self.render_file(pdf_filename, xml_string, type = :danfe, new_options = {})
    self.options = new_options if !new_options.empty?

    pdf = generatePDF(xml_string, type)
    pdf.render_file pdf_filename
  end

  def self.options
    @options ||= RubyDanfe::Options.new
  end

  def self.options=(new_options = {})
    @options = RubyDanfe::Options.new(new_options)
  end

  private
    def self.generatePDF(xml_string, type = :danfe, new_options = {})
      self.options = new_options if !new_options.empty?

      xml = XML.new(xml_string)

      generator =
        case type
          when :danfe then DanfeGenerator.new(xml)
          when :danfe_nfce then DanfeNfceGenerator.new(xml)
          when :dacte then DacteGenerator.new(xml)
          when :danfse then DanfseGenerator.new(xml)
          when :dacteos then DacteosGenerator.new(xml)
          else raise "unknown type #{type}"
        end
      generator.generatePDF
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby_danfe-1.15.4 lib/ruby_danfe/ruby_danfe.rb
ruby_danfe-1.15.2 lib/ruby_danfe/ruby_danfe.rb
ruby_danfe-1.15.1 lib/ruby_danfe/ruby_danfe.rb
ruby_danfe-1.15.0 lib/ruby_danfe/ruby_danfe.rb