Class: Strokes::Barcode
- Inherits:
-
Object
- Object
- Strokes::Barcode
- Defined in:
- lib/strokes/barcode.rb
Instance Method Summary collapse
-
#initialize(symbol, content, options = '') ⇒ Barcode
constructor
A new instance of Barcode.
-
#save(filename, options = {}) ⇒ Object
filename should include the full path options: - width: width of the resulting png.
Constructor Details
#initialize(symbol, content, options = '') ⇒ Barcode
Returns a new instance of Barcode.
9 10 11 12 13 14 |
# File 'lib/strokes/barcode.rb', line 9 def initialize(symbol, content, = '') raise IllegalSymbolError, symbol.to_s unless VALID_SYMBOLS.include?(symbol.to_sym) @symbol = symbol.to_sym @content = content @options = end |
Instance Method Details
#save(filename, options = {}) ⇒ Object
filename should include the full path options:
- width: width of the resulting png
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/strokes/barcode.rb', line 19 def save(filename, = {}) ps = send(@symbol) = [ "-dBATCH", "-dNOPAUSE", "-q", "-dTextAlphaBits=4", "-dSAFER", "-sOutputFile=#{filename}", "-sDEVICE=pnggray" ] = "#{File.(File.dirname(__FILE__))}/barcode.ps" sub = Subexec.run "gs #{.join(" ")} #{} -c '#{ps}'" raise(GhostScriptError, sub.output) unless sub.exitstatus == 0 resize_method = (ps =~ /includetext/ ? "-scale" : "-sample") = [ "-trim", "-bordercolor white", "-border 10%", [:width] ? "#{resize_method} #{[:width]}" : nil ].compact sub = Subexec.run "mogrify #{.join(' ')} #{filename}" raise(ImageMagickError, sub.output) unless sub.exitstatus == 0 File.open(filename, 'r') end |