Class | Barby::Barcode |
In: |
lib/barby/barcode.rb
|
Parent: | Object |
The base class for all barcodes. It includes some method_missing magic that is used to find registered outputters.
The only interface requirement of a barcode class is that is has an encoding method that returns a string consisting of 1s and 0s representing the barcode‘s "black" and "white" parts. One digit is the width of the "X dimension"; that is, "101100" represents a single-width bar followed by a single-width space, then a bar and a space twice that width.
Example implementation:
class StaticBarcode < Barby::Barcode1D def encoding '101100111000111100001' end end require 'barby/outputter/ascii_outputter' puts StaticBarcode.new.to_ascii(:height => 3) # ## ### #### # # ## ### #### # # ## ### #### #
2D implementation:
class Static2DBarcode < Barby::Barcode2D def encoding ['1010101', '010101110', '0001010100'] end end
Every barcode must have an encoding method. This method returns a string containing a series of 1 and 0, representing bars and spaces. One digit is the width of one "module" or X dimension.
If the barcode is 2D, it returns an array of strings representing each line in the barcode
# File lib/barby/barcode.rb, line 44 44: def encoding 45: raise NotImplementedError, 'Every barcode should implement this method' 46: end
Get the outputter class object for name
# File lib/barby/barcode.rb, line 84 84: def outputter_class_for(name) 85: self.class.outputters[name].first 86: end
Returns an instantiated outputter for name if any outputter has registered that name
# File lib/barby/barcode.rb, line 79 79: def outputter_for(name, *a, &b) 80: outputter_class_for(name).new(self, *a, &b) 81: end