rQRCode is a library for encoding QRCodes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
There is a rQRCode Rubyforge project setup. You can also view the rQRCode documentation or just jump straight into installing the gem.
sudo gem install rqrcode
A quick simple example in the console:
=> require 'rubygems' => require 'rqrcode' => qr = RQRCode::QRCode.new('hello world') >> #<RQRCode::QRCode:0x32a9 ...... => puts qr.to_s >> xxxxxxx xxxx xxxxxxx x x x xxx x x x xxx x x xx xx x xxx x x xxx x xx x x x xxx x .....
Also, here is a quick example of using it in a Ruby on Rails project:
# Controller
require 'rqrcode'
def qrcode
@qr = RQRCode::QRCode.new('hello world')
end
# View
<style type="text/css">
table {
border-width: 0;
border-style: none;
border-color: #0000ff;
border-collapse: collapse;
}
td {
border-width: 0;
border-style: none;
border-color: #0000ff;
border-collapse: collapse;
padding: 0;
margin: 0;
width: 10px;
height: 10px;
}
td.black { background-color: #000; }
td.white { background-color: #fff; }
</style>
<table>
<% @qr.modules.each_index do |x| -%>
<tr>
<% @qr.modules.each_index do |y| -%>
<% if @qr.is_dark(x,y) -%>
<td class="black"/>
<% else -%>
<td class="white"/>
<% end -%>
<% end -%>
</tr>
<% end -%>
</table>The example above will give you the representation you see below. Simple Huh?
You can download this project in either zip or tar formats.
View or fork the source via GitHub: http://github.com/whomwah/rqrcode/tree/master. Here is the Public Clone URL:
git clone git://github.com/whomwah/rqrcode.git
Launched: Sunday, February 24th, 2008
Author: Duncan Robertson [http://whomwah.com]
