Class: Mead::Barcode
- Inherits:
-
Object
- Object
- Mead::Barcode
- Defined in:
- lib/mead/barcode.rb
Instance Attribute Summary collapse
-
#mead ⇒ Object
Returns the value of attribute mead.
Instance Method Summary collapse
-
#initialize(identifier) ⇒ Barcode
constructor
A new instance of Barcode.
- #label_text ⇒ Object
- #output_barcode(directory) ⇒ Object
- #output_label(directory) ⇒ Object
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
#mead ⇒ Object
Returns the value of attribute mead.
3 4 5 |
# File 'lib/mead/barcode.rb', line 3 def mead @mead end |
Instance Method Details
#label_text ⇒ Object
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 (directory) bc = Gbarcode.(@mead.mead) bc.scalef = 0.5 bc.margin = 25 Gbarcode.(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.(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 = (directory) begin `convert #{png_path} #{text_path} -append #{label_path}` rescue end File.delete(png_path) File.delete(text_path) label_path end |