Issue 537, don't return UPC-A for EAN-13 starting with 0 when UPC-A isn't allowed
[zxing.git] / jruby / README.textile
1 h2. Decode QR Codes
2
3 p. "QR code":http://en.wikipedia.org/wiki/QR_Code generation is well served in the Ruby community, but decoding seems to be stuck in the Java world. This is an attempt to bridge the gap by wrapping the "ZXing":http://code.google.com/p/zxing/ library with JRuby. ZXing conveniently decodes a plethora of barcodes. Their site has a complete list.
4
5 h2. Requirements
6
7     * JRuby (tested with 1.4.0)
8     * shoulda (for testing)
9
10 h2. Using the ZXing module/singleton.
11
12 <pre>
13   <code>
14     require 'zxing'
15
16     # You can decode a URL...
17     ZXing.decode 'http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif'
18
19     # ... or a file path...
20     ZXing.decode '/Users/ecin/qrcode.png'
21
22     # ... or a File object...
23     ZXing.decode File.open('qrcode.png')
24
25     # ... or anything that returns a URL or file path when #path or #to_s 
26     # is called on it.
27     class Image
28       attr_reader :path
29       def initialize(path); @path = path end
30     end
31
32     image = Image.new('qrcode.png')
33     ZXing.decode image
34       
35     # #decode returns nil if it can't decode the image.
36     ZXing.decode 'image_without_a_code.png'
37     # => nil
38
39     # #decode! will raise an error if it can't decode the image.
40     ZXing.decode! 'image_without_a_code.png'
41     # => NativeException
42
43     # Feel free to include ZXing to shorten the call.
44     include ZXing
45
46     decode 'qrcode.png'
47   </code>
48 </pre>
49
50 h2. Including the Decodable module.
51
52 p. A Decodable module is included (pun intended) to ease using the library with objects that return the URL or file path to decode when #path or #to_s is called.
53
54 <pre>
55   <code>
56      require 'zxing/decodable'
57
58      class File
59        include Decodable
60      end
61
62      file = File.open('qrcode.png')
63      file.decode
64    </code>
65 </pre>