rqrcode 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.md +119 -0
- data/lib/rqrcode/qrcode/qr_code.rb +58 -52
- data/lib/rqrcode/qrcode/qr_rs_block.rb +8 -8
- data/lib/rqrcode/qrcode/qr_util.rb +14 -14
- data/lib/rqrcode/version.rb +1 -1
- data/rqrcode.gemspec +1 -1
- data/test/test_rqrcode.rb +4 -4
- metadata +6 -6
- data/README.org +0 -108
data/CHANGELOG
CHANGED
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# rQRCode, Encode QRCodes
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
|
6
|
+
|
7
|
+
Let's clear up some rQRCode stuff.
|
8
|
+
|
9
|
+
* rQRCode is a __standalone library__ It requires no other libraries. Just Ruby!
|
10
|
+
* It is an encoding library. You can't decode QR codes with it.
|
11
|
+
* The interface is simple and assumes you just want to encode a string into a QR code
|
12
|
+
* QR code is trademarked by Denso Wave inc
|
13
|
+
|
14
|
+
## Resources
|
15
|
+
|
16
|
+
* wikipedia:: http://en.wikipedia.org/wiki/QR_Code
|
17
|
+
* Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
|
18
|
+
* kaywa:: http://qrcode.kaywa.com
|
19
|
+
|
20
|
+
## Installing
|
21
|
+
|
22
|
+
You may get the latest stable version from Rubygems.
|
23
|
+
|
24
|
+
gem install rqrcode
|
25
|
+
|
26
|
+
You can also get the latest source from http://github.com/whomwah/rqrcode
|
27
|
+
|
28
|
+
git clone git://github.com/whomwah/rqrcode.git
|
29
|
+
|
30
|
+
## Tests
|
31
|
+
|
32
|
+
To run the tests:
|
33
|
+
|
34
|
+
$ rake
|
35
|
+
|
36
|
+
## Loading rQRCode Itself
|
37
|
+
|
38
|
+
You have installed the gem already, yeah?
|
39
|
+
|
40
|
+
require 'rubygems'
|
41
|
+
require 'rqrcode'
|
42
|
+
|
43
|
+
## Simple QRCode generation to screen
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
47
|
+
puts qr.to_s
|
48
|
+
#
|
49
|
+
# Prints:
|
50
|
+
# xxxxxxx x x x x x xx xxxxxxx
|
51
|
+
# x x xxx xxxxxx xxx x x
|
52
|
+
# x xxx x xxxxx x xx x xxx x
|
53
|
+
# ... etc
|
54
|
+
```
|
55
|
+
|
56
|
+
## Simple QRCode generation to template (RubyOnRails)
|
57
|
+
|
58
|
+
```erb
|
59
|
+
# Controller
|
60
|
+
@qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
61
|
+
|
62
|
+
# View: (minimal styling added)
|
63
|
+
<style type="text/css">
|
64
|
+
table {
|
65
|
+
border-width: 0;
|
66
|
+
border-style: none;
|
67
|
+
border-color: #0000ff;
|
68
|
+
border-collapse: collapse;
|
69
|
+
}
|
70
|
+
td {
|
71
|
+
border-width: 0;
|
72
|
+
border-style: none;
|
73
|
+
border-color: #0000ff;
|
74
|
+
border-collapse: collapse;
|
75
|
+
padding: 0;
|
76
|
+
margin: 0;
|
77
|
+
width: 10px;
|
78
|
+
height: 10px;
|
79
|
+
}
|
80
|
+
td.black { background-color: #000; }
|
81
|
+
td.white { background-color: #fff; }
|
82
|
+
</style>
|
83
|
+
|
84
|
+
<table>
|
85
|
+
<% @qr.modules.each_index do |x| %>
|
86
|
+
<tr>
|
87
|
+
<% @qr.modules.each_index do |y| %>
|
88
|
+
<% if @qr.dark?(x,y) %>
|
89
|
+
<td class="black"/>
|
90
|
+
<% else %>
|
91
|
+
<td class="white"/>
|
92
|
+
<% end %>
|
93
|
+
<% end %>
|
94
|
+
</tr>
|
95
|
+
<% end %>
|
96
|
+
</table>
|
97
|
+
```
|
98
|
+
|
99
|
+
## Authors
|
100
|
+
|
101
|
+
Original author: Duncan Robertson
|
102
|
+
|
103
|
+
Special thanks to the following people for submitting patches:
|
104
|
+
|
105
|
+
* [Gioele Barabucci](https://github.com/gioele)
|
106
|
+
* [Rob la Lau](https://github.com/ohreally)
|
107
|
+
* [Chris Mowforth](http://blog.99th.st)
|
108
|
+
* [Tore Darell](http://tore.darell.no)
|
109
|
+
* [Daniel Schierbeck](https://github.com/dasch)
|
110
|
+
* Vladislav Gorodetskiy
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
* Fork the project
|
114
|
+
* Send a pull request
|
115
|
+
* Don't touch the .gemspec, I'll do that when I release a new version
|
116
|
+
|
117
|
+
## Copyright
|
118
|
+
|
119
|
+
MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|
@@ -47,6 +47,9 @@ module RQRCode #:nodoc:
|
|
47
47
|
Proc.new { |i,j| ((i * j) % 3 + (i + j) % 2) % 2 == 0 },
|
48
48
|
]
|
49
49
|
|
50
|
+
QRPOSITIONPATTERNLENGTH = (7 + 1) * 2 + 1
|
51
|
+
QRFORMATINFOLENGTH = 15
|
52
|
+
|
50
53
|
# StandardErrors
|
51
54
|
|
52
55
|
class QRCodeArgumentError < ArgumentError; end
|
@@ -95,8 +98,8 @@ module RQRCode #:nodoc:
|
|
95
98
|
|
96
99
|
@data = string
|
97
100
|
@error_correct_level = QRERRORCORRECTLEVEL[level]
|
98
|
-
@
|
99
|
-
@module_count = @
|
101
|
+
@version = size
|
102
|
+
@module_count = @version * 4 + QRPOSITIONPATTERNLENGTH
|
100
103
|
@modules = Array.new( @module_count )
|
101
104
|
@data_list = QR8bitByte.new( @data )
|
102
105
|
@data_cache = nil
|
@@ -113,7 +116,7 @@ module RQRCode #:nodoc:
|
|
113
116
|
#
|
114
117
|
|
115
118
|
def is_dark( row, col )
|
116
|
-
if row
|
119
|
+
if !row.between?(0, @module_count - 1) || !col.between?(0, @module_count - 1)
|
117
120
|
raise QRCodeRunTimeError, "Invalid row/column pair: #{row}, #{col}"
|
118
121
|
end
|
119
122
|
@modules[row][col]
|
@@ -163,29 +166,33 @@ module RQRCode #:nodoc:
|
|
163
166
|
protected
|
164
167
|
|
165
168
|
def make #:nodoc:
|
169
|
+
prepare_common_patterns
|
166
170
|
make_impl( false, get_best_mask_pattern )
|
167
171
|
end
|
168
172
|
|
169
173
|
private
|
170
174
|
|
175
|
+
def prepare_common_patterns
|
176
|
+
@modules.map! { |row| Array.new(@module_count) }
|
171
177
|
|
172
|
-
|
178
|
+
place_position_probe_pattern(0, 0)
|
179
|
+
place_position_probe_pattern(@module_count - 7, 0)
|
180
|
+
place_position_probe_pattern(0, @module_count - 7)
|
181
|
+
place_position_adjust_pattern
|
182
|
+
place_timing_pattern
|
173
183
|
|
174
|
-
|
175
|
-
|
176
|
-
end
|
184
|
+
@common_patterns = @modules.map(&:clone)
|
185
|
+
end
|
177
186
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
setup_type_info( test, mask_pattern )
|
184
|
-
setup_type_number( test ) if @type_number >= 7
|
187
|
+
def make_impl( test, mask_pattern ) #:nodoc:
|
188
|
+
@modules = @common_patterns.map(&:clone)
|
189
|
+
|
190
|
+
place_format_info(test, mask_pattern)
|
191
|
+
place_version_info(test) if @version >= 7
|
185
192
|
|
186
193
|
if @data_cache.nil?
|
187
194
|
@data_cache = QRCode.create_data(
|
188
|
-
@
|
195
|
+
@version, @error_correct_level, @data_list
|
189
196
|
)
|
190
197
|
end
|
191
198
|
|
@@ -193,16 +200,19 @@ module RQRCode #:nodoc:
|
|
193
200
|
end
|
194
201
|
|
195
202
|
|
196
|
-
def
|
197
|
-
(
|
198
|
-
next if (
|
199
|
-
|
200
|
-
|
201
|
-
if
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
def place_position_probe_pattern( row, col ) #:nodoc:
|
204
|
+
(-1..7).each do |r|
|
205
|
+
next if !(row + r).between?(0, @module_count - 1)
|
206
|
+
|
207
|
+
(-1..7).each do |c|
|
208
|
+
next if !(col + c).between?(0, @module_count - 1)
|
209
|
+
|
210
|
+
is_vert_line = (r.between?(0, 6) && (c == 0 || c == 6))
|
211
|
+
is_horiz_line = (c.between?(0, 6) && (r == 0 || r == 6))
|
212
|
+
is_square = r.between?(2,4) && c.between?(2, 4)
|
213
|
+
|
214
|
+
is_part_of_probe = is_vert_line || is_horiz_line || is_square
|
215
|
+
@modules[row + r][col + c] = is_part_of_probe
|
206
216
|
end
|
207
217
|
end
|
208
218
|
end
|
@@ -225,30 +235,24 @@ module RQRCode #:nodoc:
|
|
225
235
|
end
|
226
236
|
|
227
237
|
|
228
|
-
def
|
238
|
+
def place_timing_pattern #:nodoc:
|
229
239
|
( 8...@module_count - 8 ).each do |i|
|
230
240
|
@modules[i][6] = @modules[6][i] = i % 2 == 0
|
231
241
|
end
|
232
242
|
end
|
233
243
|
|
234
244
|
|
235
|
-
def
|
236
|
-
|
237
|
-
|
238
|
-
( 0...pos.size ).each do |i|
|
239
|
-
( 0...pos.size ).each do |j|
|
240
|
-
row = pos[i]
|
241
|
-
col = pos[j]
|
245
|
+
def place_position_adjust_pattern #:nodoc:
|
246
|
+
positions = QRUtil.get_pattern_positions(@version)
|
242
247
|
|
248
|
+
positions.each do |row|
|
249
|
+
positions.each do |col|
|
243
250
|
next unless @modules[row][col].nil?
|
244
251
|
|
245
252
|
( -2..2 ).each do |r|
|
246
253
|
( -2..2 ).each do |c|
|
247
|
-
|
248
|
-
|
249
|
-
else
|
250
|
-
@modules[row + r][col + c] = false
|
251
|
-
end
|
254
|
+
is_part_of_pattern = (r.abs == 2 || c.abs == 2 || ( r == 0 && c == 0 ))
|
255
|
+
@modules[row + r][col + c] = is_part_of_pattern
|
252
256
|
end
|
253
257
|
end
|
254
258
|
end
|
@@ -256,8 +260,8 @@ module RQRCode #:nodoc:
|
|
256
260
|
end
|
257
261
|
|
258
262
|
|
259
|
-
def
|
260
|
-
bits = QRUtil.
|
263
|
+
def place_version_info(test) #:nodoc:
|
264
|
+
bits = QRUtil.get_bch_version(@version)
|
261
265
|
|
262
266
|
( 0...18 ).each do |i|
|
263
267
|
mod = ( !test && ( (bits >> i) & 1) == 1 )
|
@@ -267,30 +271,32 @@ module RQRCode #:nodoc:
|
|
267
271
|
end
|
268
272
|
|
269
273
|
|
270
|
-
def
|
274
|
+
def place_format_info(test, mask_pattern) #:nodoc:
|
271
275
|
data = (@error_correct_level << 3 | mask_pattern)
|
272
|
-
bits = QRUtil.
|
276
|
+
bits = QRUtil.get_bch_format_info(data)
|
273
277
|
|
274
|
-
|
278
|
+
QRFORMATINFOLENGTH.times do |i|
|
275
279
|
mod = (!test && ( (bits >> i) & 1) == 1)
|
276
280
|
|
277
281
|
# vertical
|
278
282
|
if i < 6
|
279
|
-
|
283
|
+
row = i
|
280
284
|
elsif i < 8
|
281
|
-
|
285
|
+
row = i + 1
|
282
286
|
else
|
283
|
-
|
287
|
+
row = @module_count - 15 + i
|
284
288
|
end
|
289
|
+
@modules[row][8] = mod
|
285
290
|
|
286
291
|
# horizontal
|
287
292
|
if i < 8
|
288
|
-
|
293
|
+
col = @module_count - i - 1
|
289
294
|
elsif i < 9
|
290
|
-
|
295
|
+
col = 15 - i - 1 + 1
|
291
296
|
else
|
292
|
-
|
297
|
+
col = 15 - i - 1
|
293
298
|
end
|
299
|
+
@modules[8][col] = mod
|
294
300
|
end
|
295
301
|
|
296
302
|
# fixed module
|
@@ -346,14 +352,14 @@ module RQRCode #:nodoc:
|
|
346
352
|
return max_data_bytes * 8
|
347
353
|
end
|
348
354
|
|
349
|
-
def QRCode.create_data(
|
350
|
-
rs_blocks = QRRSBlock.get_rs_blocks(
|
355
|
+
def QRCode.create_data(version, error_correct_level, data_list) #:nodoc:
|
356
|
+
rs_blocks = QRRSBlock.get_rs_blocks(version, error_correct_level)
|
351
357
|
buffer = QRBitBuffer.new
|
352
358
|
|
353
359
|
data = data_list
|
354
360
|
buffer.put( data.mode, 4 )
|
355
361
|
buffer.put(
|
356
|
-
data.get_length, QRUtil.get_length_in_bits(
|
362
|
+
data.get_length, QRUtil.get_length_in_bits(data.mode, version)
|
357
363
|
)
|
358
364
|
data.write( buffer )
|
359
365
|
|
@@ -268,12 +268,12 @@ RQRCode::QRRSBlock::RS_BLOCK_TABLE = [
|
|
268
268
|
|
269
269
|
]
|
270
270
|
|
271
|
-
def QRRSBlock.get_rs_blocks(
|
272
|
-
rs_block = QRRSBlock.get_rs_block_table(
|
271
|
+
def QRRSBlock.get_rs_blocks(version, error_correct_level)
|
272
|
+
rs_block = QRRSBlock.get_rs_block_table(version, error_correct_level)
|
273
273
|
|
274
274
|
if rs_block.nil?
|
275
275
|
raise QRCodeRunTimeError,
|
276
|
-
"bad rsblock @
|
276
|
+
"bad rsblock @ version: #{version}/error_correct_level:#{error_correct_level}"
|
277
277
|
end
|
278
278
|
|
279
279
|
length = rs_block.size / 3
|
@@ -293,16 +293,16 @@ RQRCode::QRRSBlock::RS_BLOCK_TABLE = [
|
|
293
293
|
end
|
294
294
|
|
295
295
|
|
296
|
-
def QRRSBlock.get_rs_block_table(
|
296
|
+
def QRRSBlock.get_rs_block_table(version, error_correct_level)
|
297
297
|
case error_correct_level
|
298
298
|
when QRERRORCORRECTLEVEL[:l]
|
299
|
-
QRRSBlock::RS_BLOCK_TABLE[(
|
299
|
+
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 0]
|
300
300
|
when QRERRORCORRECTLEVEL[:m]
|
301
|
-
QRRSBlock::RS_BLOCK_TABLE[(
|
301
|
+
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 1]
|
302
302
|
when QRERRORCORRECTLEVEL[:q]
|
303
|
-
QRRSBlock::RS_BLOCK_TABLE[(
|
303
|
+
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 2]
|
304
304
|
when QRERRORCORRECTLEVEL[:h]
|
305
|
-
QRRSBlock::RS_BLOCK_TABLE[(
|
305
|
+
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 3]
|
306
306
|
else
|
307
307
|
nil
|
308
308
|
end
|
@@ -73,7 +73,7 @@ module RQRCode #:nodoc:
|
|
73
73
|
QRMODE[:mode_kanji] => [8, 10, 12],
|
74
74
|
}
|
75
75
|
|
76
|
-
def QRUtil.
|
76
|
+
def QRUtil.get_bch_format_info( data )
|
77
77
|
d = data << 10
|
78
78
|
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15) >= 0
|
79
79
|
d ^= (G15 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15)))
|
@@ -82,7 +82,7 @@ module RQRCode #:nodoc:
|
|
82
82
|
end
|
83
83
|
|
84
84
|
|
85
|
-
def QRUtil.
|
85
|
+
def QRUtil.get_bch_version(data)
|
86
86
|
d = data << 12
|
87
87
|
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18) >= 0
|
88
88
|
d ^= (G18 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18)))
|
@@ -103,8 +103,8 @@ module RQRCode #:nodoc:
|
|
103
103
|
end
|
104
104
|
|
105
105
|
|
106
|
-
def QRUtil.
|
107
|
-
PATTERN_POSITION_TABLE[
|
106
|
+
def QRUtil.get_pattern_positions(version)
|
107
|
+
PATTERN_POSITION_TABLE[version - 1]
|
108
108
|
end
|
109
109
|
|
110
110
|
|
@@ -128,27 +128,27 @@ module RQRCode #:nodoc:
|
|
128
128
|
end
|
129
129
|
|
130
130
|
|
131
|
-
def QRUtil.get_length_in_bits(mode,
|
131
|
+
def QRUtil.get_length_in_bits(mode, version)
|
132
132
|
if !QRMODE.value?(mode)
|
133
133
|
raise QRCodeRunTimeError, "Unknown mode: #{mode}"
|
134
134
|
end
|
135
135
|
|
136
|
-
if
|
137
|
-
raise QRCodeRunTimeError, "Unknown
|
136
|
+
if version > 40
|
137
|
+
raise QRCodeRunTimeError, "Unknown version: #{version}"
|
138
138
|
end
|
139
139
|
|
140
|
-
if 1
|
140
|
+
if version.between?(1, 9)
|
141
141
|
# 1 - 9
|
142
|
-
|
143
|
-
elsif
|
142
|
+
macro_version = 0
|
143
|
+
elsif version <= 26
|
144
144
|
# 10 - 26
|
145
|
-
|
146
|
-
elsif
|
145
|
+
macro_version = 1
|
146
|
+
elsif version <= 40
|
147
147
|
# 27 - 40
|
148
|
-
|
148
|
+
macro_version = 2
|
149
149
|
end
|
150
150
|
|
151
|
-
return BITS_FOR_MODE[mode][
|
151
|
+
return BITS_FOR_MODE[mode][macro_version]
|
152
152
|
end
|
153
153
|
|
154
154
|
def QRUtil.get_lost_points(modules)
|
data/lib/rqrcode/version.rb
CHANGED
data/rqrcode.gemspec
CHANGED
@@ -22,7 +22,7 @@ EOF
|
|
22
22
|
s.add_development_dependency("bundler", ">= 1.0.0")
|
23
23
|
|
24
24
|
s.has_rdoc = true
|
25
|
-
s.extra_rdoc_files = ["README.
|
25
|
+
s.extra_rdoc_files = ["README.md", "CHANGELOG", "LICENSE"]
|
26
26
|
s.files = `git ls-files`.split("\n")
|
27
27
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
28
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/test/test_rqrcode.rb
CHANGED
@@ -71,10 +71,10 @@ class QRCodeTest < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
def test_to_s
|
73
73
|
qr = RQRCode::QRCode.new( 'duncan', :size => 1 )
|
74
|
-
assert_equal
|
75
|
-
assert_equal
|
76
|
-
|
77
|
-
assert_equal qr.to_s( :true => '@' )[0..21]
|
74
|
+
assert_equal "xxxxxxx xx x xxxxxxx\n", qr.to_s[0..21]
|
75
|
+
assert_equal "qqqqqqqnqqnqnnqqqqqqq\n",
|
76
|
+
qr.to_s( :true => 'q', :false => 'n' )[0..21]
|
77
|
+
assert_equal "@@@@@@@ @@ @ @@@@@@@\n", qr.to_s( :true => '@' )[0..21]
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_rszf_error_not_thrown
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rqrcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Duncan Robertson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-16 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,7 +60,7 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
|
62
62
|
extra_rdoc_files:
|
63
|
-
- README.
|
63
|
+
- README.md
|
64
64
|
- CHANGELOG
|
65
65
|
- LICENSE
|
66
66
|
files:
|
@@ -68,7 +68,7 @@ files:
|
|
68
68
|
- CHANGELOG
|
69
69
|
- Gemfile
|
70
70
|
- LICENSE
|
71
|
-
- README.
|
71
|
+
- README.md
|
72
72
|
- Rakefile
|
73
73
|
- lib/rqrcode.rb
|
74
74
|
- lib/rqrcode/core_ext.rb
|
data/README.org
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
* rQRCode, Encode QRCodes
|
2
|
-
|
3
|
-
** Overview
|
4
|
-
|
5
|
-
rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
|
6
|
-
|
7
|
-
Let's clear up some rQRCode stuff.
|
8
|
-
|
9
|
-
- rQRCode is a *standalone library*. It requires no other libraries. Just Ruby!
|
10
|
-
- It is an encoding library. You can't decode QR codes with it.
|
11
|
-
- The interface is simple and assumes you just want to encode a string into a QR code
|
12
|
-
- QR code is trademarked by Denso Wave inc
|
13
|
-
|
14
|
-
** Resources
|
15
|
-
|
16
|
-
- wikipedia:: http://en.wikipedia.org/wiki/QR_Code
|
17
|
-
- Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
|
18
|
-
- kaywa:: http://qrcode.kaywa.com
|
19
|
-
|
20
|
-
** Installing
|
21
|
-
|
22
|
-
You may get the latest stable version from Rubygems.
|
23
|
-
|
24
|
-
: $ gem install rqrcode
|
25
|
-
|
26
|
-
You can also get the source from http://github.com/whomwah/rqrcode
|
27
|
-
|
28
|
-
: $ git clone git://github.com/whomwah/rqrcode.git
|
29
|
-
|
30
|
-
** Loading rQRCode Itself
|
31
|
-
|
32
|
-
You have installed the gem already, yeah?
|
33
|
-
|
34
|
-
: require 'rubygems'
|
35
|
-
: require 'rqrcode'
|
36
|
-
|
37
|
-
** Simple QRCode generation to screen
|
38
|
-
|
39
|
-
: qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
40
|
-
: puts qr.to_s
|
41
|
-
: #
|
42
|
-
: # Prints:
|
43
|
-
: # xxxxxxx x x x x x xx xxxxxxx
|
44
|
-
: # x x xxx xxxxxx xxx x x
|
45
|
-
: # x xxx x xxxxx x xx x xxx x
|
46
|
-
: # ... etc
|
47
|
-
|
48
|
-
** Simple QRCode generation to template (RubyOnRails)
|
49
|
-
|
50
|
-
: # Controller
|
51
|
-
: @qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
52
|
-
:
|
53
|
-
: # View: (minimal styling added)
|
54
|
-
: <style type="text/css">
|
55
|
-
: table {
|
56
|
-
: border-width: 0;
|
57
|
-
: border-style: none;
|
58
|
-
: border-color: #0000ff;
|
59
|
-
: border-collapse: collapse;
|
60
|
-
: }
|
61
|
-
: td {
|
62
|
-
: border-width: 0;
|
63
|
-
: border-style: none;
|
64
|
-
: border-color: #0000ff;
|
65
|
-
: border-collapse: collapse;
|
66
|
-
: padding: 0;
|
67
|
-
: margin: 0;
|
68
|
-
: width: 10px;
|
69
|
-
: height: 10px;
|
70
|
-
: }
|
71
|
-
: td.black { background-color: #000; }
|
72
|
-
: td.white { background-color: #fff; }
|
73
|
-
: </style>
|
74
|
-
:
|
75
|
-
: <table>
|
76
|
-
: <% @qr.modules.each_index do |x| %>
|
77
|
-
: <tr>
|
78
|
-
: <% @qr.modules.each_index do |y| %>
|
79
|
-
: <% if @qr.dark?(x,y) %>
|
80
|
-
: <td class="black"/>
|
81
|
-
: <% else %>
|
82
|
-
: <td class="white"/>
|
83
|
-
: <% end %>
|
84
|
-
: <% end %>
|
85
|
-
: </tr>
|
86
|
-
: <% end %>
|
87
|
-
: </table>
|
88
|
-
|
89
|
-
** Authors
|
90
|
-
|
91
|
-
Original author: Duncan Robertson
|
92
|
-
|
93
|
-
Special thanks to the following people for submitting patches:
|
94
|
-
|
95
|
-
- Gioele Barabucci
|
96
|
-
- Rob la Lau
|
97
|
-
- Chris Mowforth
|
98
|
-
- Tore Darell
|
99
|
-
- Vladislav Gorodetskiy
|
100
|
-
|
101
|
-
** Contributing
|
102
|
-
- Fork the project
|
103
|
-
- Send a pull request
|
104
|
-
- Don't touch the .gemspec, I'll do that when I release a new version
|
105
|
-
|
106
|
-
** Copyright
|
107
|
-
|
108
|
-
MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|