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.
sudo gem install rqrcode
The documentation is available over on the RubyGems website.
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.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?
Launched: Sunday, February 24th, 2008
Author: Duncan Robertson [http://whomwah.com]
