Class: OutwoodLabels::Generate

Inherits:
Object
  • Object
show all
Includes:
Callable
Defined in:
lib/outwood_labels/generate.rb

Instance Method Summary collapse

Methods included from Callable

included

Constructor Details

#initialize(data, outfile, template, config = {}) ⇒ Generate

Returns a new instance of Generate.

Parameters:



13
14
15
16
17
18
# File 'lib/outwood_labels/generate.rb', line 13

def initialize(data, outfile, template, config = {})
  @config = config
  @data = data
  @outfile = outfile
  @template = template
end

Instance Method Details

#callObject

Generate PDF and write to disk

Raises:

  • (Error)

    when required columns are missing



22
23
24
25
26
27
# File 'lib/outwood_labels/generate.rb', line 22

def call
  check_header if @template
  config = @config.merge({ layout: @template.layout })
  labels = Prawn::LabelSheet.new @data, **config, &@template.method(:evaluate)
  labels.document.render_file(@outfile)
end