class Zint::Barcode

A base class to represent the barcode being encoded

Attributes

bctype[RW]

The type of barcode generated (e.g. UPC, QRCode, Data Matrix)

path[R]

The output file path

value[RW]

The encoded value of the barcode

zint_symbol[R]

Access for the underlying FFI ManagedStruct of the Zint C struct

Public Class Methods

new(value, bctype=Zint::BARCODE_CODE128, *options) click to toggle source
# File lib/zint/barcode.rb, line 13
def initialize(value, bctype=Zint::BARCODE_CODE128, *options)
  if options.kind_of? Array
    options = options.shift
  end
  options ||= {}
  @zint_symbol = Zint::Wrapper.create(bctype)
  @bctype = bctype
  @value = value
  @encoded = false
  if options[:path]
    @path = options[:path]
    @zint_symbol[:outfile]= @path
  else
    @path = File.join(Dir.pwd,  "out.png")
    @zint_symbol[:outfile]= @path
  end
end

Public Instance Methods

buffer!() click to toggle source
# File lib/zint/barcode.rb, line 55
def buffer!
  tmp = File.join(Dir.tmpdir, File.basename(@path))
  @zint_symbol[:outfile] = tmp
  print!
  @zint_symbol[:outfile] = @path
  buffer = File.read(tmp)
  File.unlink(tmp)
  return buffer
end
encode!() click to toggle source
# File lib/zint/barcode.rb, line 38
def encode!
  return if @encoded
  err = Zint::Wrapper.zint_encode(@zint_symbol, @value, 0)
  if Zint::ERR[:err]
    raise Zint::Exception.new(@zint_symbol[:errtxt])
  end
  @encoded = true
end
path=(fspath) click to toggle source
# File lib/zint/barcode.rb, line 31
def path=(fspath)
  @path = fspath
  @zint_symbol[:outfile] = @path
  @encoded = false
  return @path
end
print!() click to toggle source