Class: Zint::Barcode
- Inherits:
-
Object
- Object
- Zint::Barcode
- Defined in:
- lib/zint/barcode.rb
Overview
A base class to represent the barcode being encoded
Direct Known Subclasses
DataMatrix, Ean, QRCode, Upc
Instance Attribute Summary collapse
-
#bctype ⇒ Object
The type of barcode generated (e.g. UPC, QRCode, Data Matrix).
-
#path ⇒ Object
The output file path.
-
#value ⇒ Object
The encoded value of the barcode.
-
#zint_symbol ⇒ Object
readonly
Access for the underlying FFI ManagedStruct of the Zint C struct.
Instance Method Summary collapse
- #buffer! ⇒ Object
- #encode! ⇒ Object
-
#initialize(value, bctype = Zint::BARCODE_CODE128, *options) ⇒ Barcode
constructor
A new instance of Barcode.
- #print! ⇒ Object
Constructor Details
#initialize(value, bctype = Zint::BARCODE_CODE128, *options) ⇒ Barcode
Returns a new instance of Barcode.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zint/barcode.rb', line 13 def initialize(value, bctype=Zint::BARCODE_CODE128, *) if .kind_of? Array = .shift end ||= {} @zint_symbol = Zint::Wrapper.create(bctype) @bctype = bctype @value = value @encoded = false if [:path] @path = [:path] @zint_symbol[:outfile]= @path else @path = File.join(Dir.pwd, "out.png") @zint_symbol[:outfile]= @path end end |
Instance Attribute Details
#bctype ⇒ Object
The type of barcode generated (e.g. UPC, QRCode, Data Matrix)
7 8 9 |
# File 'lib/zint/barcode.rb', line 7 def bctype @bctype end |
#path ⇒ Object
The output file path
9 10 11 |
# File 'lib/zint/barcode.rb', line 9 def path @path end |
#value ⇒ Object
The encoded value of the barcode
5 6 7 |
# File 'lib/zint/barcode.rb', line 5 def value @value end |
#zint_symbol ⇒ Object (readonly)
Access for the underlying FFI ManagedStruct of the Zint C struct
11 12 13 |
# File 'lib/zint/barcode.rb', line 11 def zint_symbol @zint_symbol end |
Instance Method Details
#buffer! ⇒ Object
55 56 57 58 59 60 61 62 63 |
# 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 |