Class: Badger::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/badger/template.rb

Defined Under Namespace

Classes: FormatError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Template

Returns a new instance of Template.



8
9
10
# File 'lib/badger/template.rb', line 8

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/badger/template.rb', line 7

def filename
  @filename
end

Instance Method Details

#absolute_pathObject



12
13
14
# File 'lib/badger/template.rb', line 12

def absolute_path
  File.expand_path(@filename)
end

#badges_per_pageObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/badger/template.rb', line 16

def badges_per_page
  @badges_per_page ||= begin
    data_fields = `pdftk '#{@filename}' dump_data_fields`
    per_page = data_fields.scan(/first_name(\d+)/).flatten.map(&:to_i).max
    if per_page.zero?
      raise FormatError, "No badges found in template #{@filename}; see badger -h"
    else
      per_page
    end
  end
end