Class: EasyInvoices::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_invoices/generator.rb

Direct Known Subclasses

Act, Invoice

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(invoice_params, file_name) ⇒ Generator

Returns a new instance of Generator.



14
15
16
17
# File 'lib/easy_invoices/generator.rb', line 14

def initialize(invoice_params, file_name)
  @invoice_params = invoice_params
  @file_name = file_name.nil? ? "#{SecureRandom.hex}.pdf" : "#{file_name}.pdf"
end

Class Method Details

.generate(invoice_params, file_name) ⇒ Object



6
7
8
# File 'lib/easy_invoices/generator.rb', line 6

def self.generate(invoice_params, file_name)
  self.new(invoice_params, file_name).process
end

.storage_dirObject



10
11
12
# File 'lib/easy_invoices/generator.rb', line 10

def self.storage_dir
  EasyInvoices.configuration.send(:"#{self.name.demodulize.downcase}_dir") || self::DIR
end

Instance Method Details

#processObject



19
20
21
22
23
24
25
26
27
# File 'lib/easy_invoices/generator.rb', line 19

def process
  check_dir

  File.open(target_file, 'wb') do |file|
    file << rendered_pdf
  end

  target_file
end