Subscribe to my Feed, follow me on Twitter, recommend me on Working With Rails or see my code on GitHub
Barby 0.2: Now with added dimension

Barby 0.2 has support for two-dimensional barcodes, and all existing outputters have been updated to work with 2D. The first supported 2D symbology is QR Code which is quite popular for mobile phone implementations and big in Japan. It uses the excellent RQRCode library by Duncan Robertson.
require 'barby'
require 'barby/outputter/png_outputter'
qrcode = Barby::QrCode.new('2D power')
File.open('qrcode.png', 'w') do |f|
f << qrcode.to_png
end
To update or install:
sudo gem install barby
The implementation of 2D support is pretty simple: 2D barcodes are considered to be 1D barcodes on top of each other. So if you’re writing a class for a 2D symbology, the difference is that your encoding method must return an array of strings instead if a single string:
class My2DBarcode < Barby::Barcode2D
def endoding
['010011', '011001', '110001']
end
end
If you’re writing an outputter that is capable of handling 2D barcodes, you just have to keep this in mind. You can use the two_dimensional? method to check if a barcode is 2D:
class MyOutputter < Barby::Outputter
def to_something
if barcode.two_dimensional?
encoding.inject(""){|s,line| s + do_something_with(line) }
else
do_something_with(encoding)
end
end
end
