rqrcode 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +1 -3
- data/CHANGELOG +5 -0
- data/README.md +17 -2
- data/TODO.md +0 -1
- data/lib/rqrcode/qrcode/qr_bit_buffer.rb +7 -0
- data/lib/rqrcode/qrcode/qr_code.rb +25 -4
- data/lib/rqrcode/qrcode/qr_numeric.rb +66 -0
- data/lib/rqrcode/version.rb +1 -1
- data/rqrcode.gemspec +1 -1
- data/test/test_rqrcode.rb +7 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c6e005cfad5a06130d1057cb3339a9536876d7
|
4
|
+
data.tar.gz: 43052e7598d0ca24b55ccdac80c112d110d6023f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da648696490c9dea757030a8f1a33ec731532704bca8707dac941729791bb1f4c7d68a39dc83bbeab0df39becc719b3b70b383c1ae88a4600ec7a6742f36a10
|
7
|
+
data.tar.gz: ed6067dc3533be6f1ebdbd3eea7e34a4caca62d868a469ad09f7dbb963a72c13c1dc75ab3f29385f27317e9601a7e0e156d91cc95c9c757fe9719f7a595003fc
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
## Short changelog
|
6
6
|
|
7
|
+
*0.8.0* (Dec 18, 2015)
|
8
|
+
|
9
|
+
- Added numeric QR code support
|
10
|
+
- Dropped Ruby v1.8 support
|
11
|
+
|
7
12
|
*0.7.0* (Aug 15, 2015)
|
8
13
|
|
9
14
|
- Added shape_rendering option for as_svg
|
@@ -76,9 +81,8 @@ png = qrcode.as_png(
|
|
76
81
|
color: 'black',
|
77
82
|
size: 120,
|
78
83
|
border_modules: 4,
|
79
|
-
file: false,
|
80
84
|
module_px_size: 6,
|
81
|
-
|
85
|
+
file: nil # path to write
|
82
86
|
)
|
83
87
|
```
|
84
88
|
|
@@ -141,6 +145,17 @@ qr.modules.each do |row|
|
|
141
145
|
end
|
142
146
|
```
|
143
147
|
|
148
|
+
## Specifying QR code mode
|
149
|
+
|
150
|
+
Sometimes you may want to specify the QR code mode explicitly.
|
151
|
+
|
152
|
+
It is done via the `mode` option. Allowed values are: `number`, `alphanumeric` and `byte_8bit`.
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
qr = RQRCode::QRCode.new( '1234567890', :size => 2, :level => :m, :mode => :number )
|
156
|
+
```
|
157
|
+
|
158
|
+
|
144
159
|
## API Documentation
|
145
160
|
|
146
161
|
[http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
|
data/TODO.md
CHANGED
@@ -68,6 +68,13 @@ module RQRCode
|
|
68
68
|
put(length, QRUtil.get_length_in_bits(QRMODE[:mode_alpha_numk], @version))
|
69
69
|
|
70
70
|
end
|
71
|
+
|
72
|
+
def numeric_encoding_start(length)
|
73
|
+
|
74
|
+
put( QRMODE[:mode_number], 4 )
|
75
|
+
put(length, QRUtil.get_length_in_bits(QRMODE[:mode_number], @version))
|
76
|
+
|
77
|
+
end
|
71
78
|
|
72
79
|
def pad_until(prefered_size)
|
73
80
|
# Align on byte
|
@@ -18,6 +18,12 @@ module RQRCode #:nodoc:
|
|
18
18
|
:mode_kanji => 1 << 3
|
19
19
|
}
|
20
20
|
|
21
|
+
QRMODE_NAME = {
|
22
|
+
:number => :mode_number,
|
23
|
+
:alphanumeric => :mode_alpha_numk,
|
24
|
+
:byte_8bit => :mode_8bit_byte
|
25
|
+
}
|
26
|
+
|
21
27
|
QRERRORCORRECTLEVEL = {
|
22
28
|
:l => 1,
|
23
29
|
:m => 0,
|
@@ -84,7 +90,7 @@ module RQRCode #:nodoc:
|
|
84
90
|
# and an optional hash of any other. Here's a few examples:
|
85
91
|
#
|
86
92
|
# qr = RQRCode::QRCode.new('hello world')
|
87
|
-
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
|
93
|
+
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m, :mode => :alphanumeric )
|
88
94
|
#
|
89
95
|
|
90
96
|
class QRCode
|
@@ -99,8 +105,13 @@ module RQRCode #:nodoc:
|
|
99
105
|
# * Level :m 15% of code can be restored
|
100
106
|
# * Level :q 25% of code can be restored
|
101
107
|
# * Level :h 30% of code can be restored (default :h)
|
108
|
+
# # mode - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data):
|
109
|
+
# * :number
|
110
|
+
# * :alphanumeric
|
111
|
+
# * :byte_8bit
|
112
|
+
# * :kanji
|
102
113
|
#
|
103
|
-
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
|
114
|
+
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m, :mode => :alphanumeric )
|
104
115
|
#
|
105
116
|
|
106
117
|
def initialize( string, *args )
|
@@ -117,7 +128,8 @@ module RQRCode #:nodoc:
|
|
117
128
|
|
118
129
|
@data = string
|
119
130
|
|
120
|
-
mode =
|
131
|
+
mode = QRMODE_NAME[(options[:mode] || '').to_sym]
|
132
|
+
mode ||= QRAlphanumeric.valid_data?( @data ) ? :mode_alpha_numk : :mode_8bit_byte # deprecate?
|
121
133
|
|
122
134
|
max_size_array = QRMAXDIGITS[level][mode]
|
123
135
|
size = options[:size] || smallest_size_for(string, max_size_array)
|
@@ -130,7 +142,16 @@ module RQRCode #:nodoc:
|
|
130
142
|
@version = size
|
131
143
|
@module_count = @version * 4 + QRPOSITIONPATTERNLENGTH
|
132
144
|
@modules = Array.new( @module_count )
|
133
|
-
@data_list =
|
145
|
+
@data_list =
|
146
|
+
case mode
|
147
|
+
when :mode_number
|
148
|
+
QRNumeric.new( @data )
|
149
|
+
when :mode_alpha_numk
|
150
|
+
QRAlphanumeric.new( @data )
|
151
|
+
else
|
152
|
+
QR8bitByte.new( @data )
|
153
|
+
end
|
154
|
+
|
134
155
|
@data_cache = nil
|
135
156
|
self.make
|
136
157
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module RQRCode
|
2
|
+
|
3
|
+
NUMERIC = ['0','1','2','3','4','5','6','7','8','9'].freeze
|
4
|
+
|
5
|
+
class QRNumeric
|
6
|
+
attr_reader :mode
|
7
|
+
|
8
|
+
def initialize( data )
|
9
|
+
@mode = QRMODE[:mode_number]
|
10
|
+
|
11
|
+
raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)
|
12
|
+
|
13
|
+
@data = data;
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def get_length
|
18
|
+
@data.size
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.valid_data? data
|
22
|
+
data.each_char do |s|
|
23
|
+
return false if NUMERIC.index(s).nil?
|
24
|
+
end
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def write( buffer)
|
30
|
+
buffer.numeric_encoding_start(get_length)
|
31
|
+
|
32
|
+
(@data.size).times do |i|
|
33
|
+
if i % 3 == 0
|
34
|
+
chars = @data[i]
|
35
|
+
|
36
|
+
if @data[i + 1].present?
|
37
|
+
chars << @data[i + 1]
|
38
|
+
end
|
39
|
+
|
40
|
+
if @data[i + 2].present?
|
41
|
+
chars << @data[i + 2]
|
42
|
+
end
|
43
|
+
|
44
|
+
bit_length = get_bit_length(chars.length)
|
45
|
+
buffer.put( get_code(chars), bit_length )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
NUMBER_LENGTH = {
|
53
|
+
3 => 10,
|
54
|
+
2 => 7,
|
55
|
+
1 => 4
|
56
|
+
}.freeze
|
57
|
+
|
58
|
+
def get_bit_length(length)
|
59
|
+
NUMBER_LENGTH[length]
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_code(chars)
|
63
|
+
chars.to_i
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/rqrcode/version.rb
CHANGED
data/rqrcode.gemspec
CHANGED
data/test/test_rqrcode.rb
CHANGED
@@ -96,6 +96,13 @@ class QRCodeTest < Test::Unit::TestCase
|
|
96
96
|
assert_equal "xxxxxxx xxx xxxxxxx\n", qr.to_s[0..21]
|
97
97
|
end
|
98
98
|
|
99
|
+
def test_numeric_2_M
|
100
|
+
data = '279042272585972554922067893753871413584876543211601021503002'
|
101
|
+
|
102
|
+
qr = RQRCode::QRCode.new(data, size: 2, level: :m, mode: :number)
|
103
|
+
assert_equal "xxxxxxx x x x xxxxxxx\n", qr.to_s[0..25]
|
104
|
+
end
|
105
|
+
|
99
106
|
def test_rszf_error_not_thrown
|
100
107
|
assert RQRCode::QRCode.new('2 1058 657682')
|
101
108
|
assert RQRCode::QRCode.new("40952", :size => 1, :level => :h)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rqrcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Björn Blomqvist
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chunky_png
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
20
|
+
version: '1.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
27
|
+
version: '1.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/rqrcode/qrcode/qr_bit_buffer.rb
|
90
90
|
- lib/rqrcode/qrcode/qr_code.rb
|
91
91
|
- lib/rqrcode/qrcode/qr_math.rb
|
92
|
+
- lib/rqrcode/qrcode/qr_numeric.rb
|
92
93
|
- lib/rqrcode/qrcode/qr_polynomial.rb
|
93
94
|
- lib/rqrcode/qrcode/qr_rs_block.rb
|
94
95
|
- lib/rqrcode/qrcode/qr_util.rb
|