Sha256: e0e2303ec88cb15accc9f64ec1a69b1a551141e858cc611adbfd86aae23b2b5c

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby
#encoding: UTF-8
require 'optparse'
require 'rubygems'

#$: << File.join(File.dirname(__FILE__), '..', 'lib')
require 'barby'

options = {
  :outputter => 'Ascii',
  :outputter_method => 'to_ascii',
  :barcode => 'Code128B'
}

ARGV.options do |o|
  o.banner = "  Usage: #{File.basename(__FILE__)} [OPTIONS] data"
  o.define_head '  Generates barcodes and prints the generated output to STDOUT'

  o.separator ''
  o.separator '  EXPERIMENTAL'
  o.separator ''

  o.on('-b', '--barcode=ClassName', String, 'Barcode type (Code128B)'){|v| options[:barcode] = v }
  o.on('-o', '--outputter=ClassName', String, 'Outputter (Ascii)'){|v| options[:outputter] = v }
  o.on('-m', '--method=method_name', String, 'Outputter method (to_ascii)'){|v| options[:outputter_method] = v }

  o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
    
  o.parse!
end

#p STDIN.read
#exit

require "barby/outputter/#{options[:outputter].gsub(/[A-Z]/){|c| '_'+c.downcase }[1..-1]}_outputter"

barcode_class = Barby.const_get(options[:barcode])
barcode = barcode_class.new($*.empty? ? STDIN.read.chomp : $*[0])
outputter_class = Barby.const_get("#{options[:outputter]}Outputter")
outputter = outputter_class.new(barcode)

print eval("outputter.#{options[:outputter_method]}(#{ENV['OPTIONS']})")

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
barby-0.7.0 bin/barby
barby-0.6.9 bin/barby
barby-0.6.8 bin/barby
barby-0.6.7 bin/barby
barby-0.6.6 bin/barby
barby-0.6.5 bin/barby
barby-0.6.4 bin/barby
barby-0.6.3 bin/barby
barby-0.6.2 bin/barby
barby-0.6.1 bin/barby
barby-0.6.0 bin/barby
barby-0.5.1 bin/barby
barby-0.5.0 bin/barby
barby-0.4.5 bin/barby
barby-0.4.4 bin/barby
barby-0.4.3 bin/barby