Class: Mead::Barcode

Inherits:
Object
  • Object
show all
Defined in:
lib/mead/barcode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ Barcode

Returns a new instance of Barcode.



5
6
7
# File 'lib/mead/barcode.rb', line 5

def initialize(identifier)
  @mead = identifier
end

Instance Attribute Details

#meadObject

Returns the value of attribute mead.



3
4
5
# File 'lib/mead/barcode.rb', line 3

def mead
  @mead
end

Instance Method Details

#label_textObject



40
41
42
43
44
45
46
# File 'lib/mead/barcode.rb', line 40

def label_text
  text = [@mead.mead]
  text << @mead..first[:unittitle][0,55]
  text.last << '...' if @mead..first[:unittitle].length > 55
  text << @mead..first[:item_location]
  text.join('\n')
end

#output_barcode(directory) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mead/barcode.rb', line 9

def output_barcode(directory)
  bc = Gbarcode.barcode_create(@mead.mead)
  bc.scalef = 0.5
  bc.margin = 25
  Gbarcode.barcode_encode(bc, Gbarcode::BARCODE_128)
  #tempfile for eps version of barcode
  eps_path = File.join(directory, @mead.mead + '.eps')
  png_path = File.join(directory, @mead.mead + '-barcode.png')
  eps = File.new(eps_path, 'w')      
  Gbarcode.barcode_print(bc, eps, Gbarcode::BARCODE_OUT_EPS)
  eps.close      
  `convert +antialias #{eps_path} -background white -flatten #{png_path}`
  File.delete(eps_path)
  png_path      
end

#output_label(directory) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mead/barcode.rb', line 25

def output_label(directory)
  text_path = File.join(directory, @mead.mead + '-text.png')
  label_path = File.join(directory, @mead.mead + '-label.png')
  `convert -font fixed -pointsize 14 -background white -fill black label:"#{label_text}" #{text_path}`
  # convert *.png -resize 75% -append output.png
  png_path = output_barcode(directory)
  begin
    `convert #{png_path} #{text_path} -append #{label_path}`
  rescue
  end
  File.delete(png_path)
  File.delete(text_path)
  label_path
end