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

Methods

Public Class methods

Registers an outputter with name so that a call to name on a Barcode instance will be delegated to this outputter

Public Instance methods

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

Get the outputter class object for name

Returns an instantiated outputter for name if any outputter has registered that name

Is this barcode 2D?

Is this barcode valid?

[Validate]