rqrcode 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 537c13caf3f8d2e6896f4c4ca2e8f49aefd5a873
4
- data.tar.gz: a9ec155978d80c75928cc8a952b010f8682ad2dc
3
+ metadata.gz: 1e8b487f591272b08e4fc7379f8ff16a7819459e
4
+ data.tar.gz: 5fc8e96a42d136b0cd76941d8a77316d207208e9
5
5
  SHA512:
6
- metadata.gz: c9e472adeef166c9030acc1d3b12b3cff3578ac6283551c60822bf02178b2ab74ab82fb60178ac94b1260d73d14f8f3dbe9c540d9244d2c07a55094d216a5f24
7
- data.tar.gz: 7ea7baac645ccb7cff2dc714ff3127a9d7bdbd19e347f889efba97a04a8489ff39c0a8038e174bfe29b5ff07794c2b75cdb7d581ecb017df6d867bcca4b9b9b8
6
+ metadata.gz: e2c4d056dc95bca8bb1a268567a0f19a3d48eaaa96d6888874ee4abde3d85db7d6ae3197e840e2085651fb0ebd8ded890421174816a75d12052a29b41bfb3895
7
+ data.tar.gz: b435943576d8a4c458e7392f0d7a69ed27a7ec3a05bc449523f2141b87e5f8c03e2fca35ce8ba64887787667d65c854655e2ec8449b1e2565daa40a1ad6f94a5
data/CHANGELOG CHANGED
@@ -1,6 +1,7 @@
1
- *0.8.2* (Jan 3, 2016)
1
+ *0.9.0* (Jan 3, 2016)
2
2
 
3
- - Fix source encoding problem introduced in 0.8.1
3
+ - Added support for auto selecting qrcode size up to level 40. (only worked up to level 10 before)
4
+ - Added numeric support during auto selection of qrcode mode.
4
5
 
5
6
  *0.8.1* (Jan 3, 2016)
6
7
 
data/README.md CHANGED
@@ -6,9 +6,10 @@
6
6
 
7
7
  ## Short changelog
8
8
 
9
- *0.8.2* (Jan 3, 2016)
9
+ *0.9.0* (Jan 3, 2016)
10
10
 
11
- - Fix source encoding problem introduced in 0.8.1
11
+ - Added support for auto selecting qrcode size up to level 40. (only worked up to level 10 before)
12
+ - Added numeric support during auto selection of qrcode mode.
12
13
 
13
14
  *0.8.1* (Jan 3, 2016)
14
15
 
@@ -20,17 +21,13 @@
20
21
  - Added numeric QR code support
21
22
  - Dropped Ruby v1.8 support
22
23
 
23
- *0.7.0* (Aug 15, 2015)
24
-
25
- - Added shape_rendering option for as_svg
26
-
27
24
  ## Overview
28
25
 
29
26
  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.
30
27
 
31
28
  Let's clear up some rQRCode stuff.
32
29
 
33
- * rQRCode is a __standalone library__ It requires no other libraries. Just Ruby!
30
+ * rQRCode is a __ruby only library__ It requires no native libraries. Just Ruby!
34
31
  * It is an encoding library. You can't decode QR codes with it.
35
32
  * The interface is simple and assumes you just want to encode a string into a QR code
36
33
  * QR code is trademarked by Denso Wave inc
data/Rakefile CHANGED
@@ -3,11 +3,11 @@ require 'bundler'
3
3
 
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- desc "Run tests"
6
+ desc 'Run tests'
7
7
  Rake::TestTask.new do |t|
8
- t.libs << "lib"
9
- t.libs << "test"
10
- t.pattern = "test/**/test_*.rb"
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/test_*.rb'
11
11
  t.verbose = true
12
12
  end
13
13
 
@@ -15,7 +15,6 @@ module RQRCode #:nodoc:
15
15
  :mode_number => 1 << 0,
16
16
  :mode_alpha_numk => 1 << 1,
17
17
  :mode_8bit_byte => 1 << 2,
18
- :mode_kanji => 1 << 3
19
18
  }
20
19
 
21
20
  QRMODE_NAME = {
@@ -59,23 +58,92 @@ module RQRCode #:nodoc:
59
58
  QRFORMATINFOLENGTH = 15
60
59
 
61
60
  #http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable1-e.html
61
+ #http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable2-e.html
62
+ #http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable3-e.html
63
+ #http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable4-e.html
64
+ # Each array contains levels max chars from level 1 to level 40
62
65
  QRMAXDIGITS = {
63
- :l => {:mode_number => [41, 77, 127, 187, 255, 322, 370, 461, 552, 652],
64
- :mode_alpha_numk => [25, 47, 77, 114, 154, 195, 224, 279, 335, 395],
65
- :mode_8bit_byte => [17, 32, 53, 78, 106, 134, 154, 192, 230, 271, 321, 367, 425, 458, 520, 586, 644, 718, 792, 858],
66
- :mode_kanji => [10, 20, 32, 48, 65, 82, 95, 118, 141, 167]},
67
- :m => {:mode_number => [34, 63, 101, 149, 202, 255, 293, 365, 432, 513],
68
- :mode_alpha_numk => [20, 38, 61, 90, 122, 154, 178, 221, 262, 311],
69
- :mode_8bit_byte => [14, 26, 42, 62, 84, 106, 122, 152, 180, 213, 251, 287, 331, 362, 412, 450, 504, 560, 624, 666],
70
- :mode_kanji => [ 8, 16, 26, 38, 54, 65, 75, 93, 111, 131]},
71
- :q => {:mode_number => [27, 48, 77, 111, 144, 178, 207, 259, 312, 364],
72
- :mode_alpha_numk => [16, 29, 47, 67, 87, 108, 125, 157, 189, 221],
73
- :mode_8bit_byte => [11, 20, 32, 46, 60, 74, 86, 108, 130, 151, 177, 203, 241, 258, 292, 22, 364, 394, 442, 482],
74
- :mode_kanji => [ 7, 12, 20, 28, 37, 45, 53, 66, 80, 93]},
75
- :h => {:mode_number => [17, 34, 58, 82, 106, 139, 154, 202, 235, 288],
76
- :mode_alpha_numk => [10, 20, 35, 50, 64, 84, 93, 122, 143, 174],
77
- :mode_8bit_byte => [ 7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194, 220, 250, 280, 310, 338, 382],
78
- :mode_kanji => [ 4, 8, 15, 21, 27, 36, 39, 52, 60, 74]},
66
+ l: {
67
+ mode_number: [
68
+ 41, 77, 127, 187, 255, 322, 370, 461, 552, 652, 772,
69
+ 883, 1022, 1101, 1250, 1408, 1548, 1725, 1903, 2061,
70
+ 2232, 2409, 2620, 2812, 3057, 3283, 3514, 3669, 3909, 4158,
71
+ 4417, 4686, 4965, 5253, 5529, 5836, 6153, 6479, 6743, 7089
72
+ ],
73
+ mode_alpha_numk: [
74
+ 25, 47, 77, 114, 154, 195, 224, 279, 335, 395,
75
+ 468, 535, 619, 667, 758, 854, 938, 1046, 1153, 1249,
76
+ 1352, 1460, 1588, 1704, 1853, 1990, 2132, 2223, 2369, 2520,
77
+ 2677, 2840, 3009, 3183, 3351, 3537, 3729, 3927, 4087, 4296
78
+ ],
79
+ mode_8bit_byte: [
80
+ 17, 32, 53, 78, 106, 134, 154, 192, 230, 271,
81
+ 321, 367, 425, 458, 520, 586, 644, 718, 792, 858,
82
+ 929, 1003, 1091, 1171, 1273, 1367, 1465, 1528, 1628, 1732,
83
+ 1840, 1952, 2068, 2188, 2303, 2431, 2563, 2699, 2809, 2953
84
+ ],
85
+ },
86
+ m: {
87
+ mode_number: [
88
+ 34, 63, 101, 149, 202, 255, 293, 365, 432, 513,
89
+ 604, 691, 796, 871, 991, 1082, 1212, 1346, 1500, 1600,
90
+ 1708, 1872, 2059, 2188, 2395, 2544, 2701, 2857, 3035, 3289,
91
+ 3486, 3693, 3909, 4134, 4343, 4588, 4775, 5039, 5313, 5596,
92
+ ],
93
+ mode_alpha_numk: [
94
+ 20, 38, 61, 90, 122, 154, 178, 221, 262, 311,
95
+ 366, 419, 483, 528, 600, 656, 734, 816, 909, 970,
96
+ 1035, 1134, 1248, 1326, 1451, 1542, 1637, 1732, 1839, 1994,
97
+ 2113, 2238, 2369, 2506, 2632, 2780, 2894, 3054, 3220, 3391
98
+ ],
99
+ mode_8bit_byte: [
100
+ 14, 26, 42, 62, 84, 106, 122, 152, 180, 213,
101
+ 251, 287, 331, 362, 412, 450, 504, 560, 624, 666,
102
+ 711, 779, 857, 911, 997, 1059, 1125, 1190, 1264, 1370,
103
+ 1452, 1538, 1628, 1722, 1809, 1911, 1989, 2099, 2213, 2331
104
+ ],
105
+ },
106
+ q: {
107
+ mode_number: [
108
+ 27, 48, 77, 111, 144, 178, 207, 259, 312, 364,
109
+ 427, 489, 580, 621, 703, 775, 876, 948, 1063, 1159,
110
+ 1224, 1358, 1468, 1588, 1718, 1804, 1933, 2085, 2181, 2358,
111
+ 2473, 2670, 2805, 2949, 3081, 3244, 3417, 3599, 3791, 3993
112
+ ],
113
+ mode_alpha_numk: [
114
+ 16, 29, 47, 67, 87, 108, 125, 157, 189, 221,
115
+ 259, 296, 352, 376, 426, 470, 531, 574, 644, 702,
116
+ 742, 823, 890, 963, 1041, 1094, 1172, 1263, 1322, 1429,
117
+ 1499, 1618, 1700, 1787, 1867, 1966, 2071, 2181, 2298, 2420
118
+ ],
119
+ mode_8bit_byte: [
120
+ 11, 20, 32, 46, 60, 74, 86, 108, 130, 151,
121
+ 177, 203, 241, 258, 292, 22, 364, 394, 442, 482,
122
+ 509, 565, 611, 661, 715, 751, 805, 868, 908, 982,
123
+ 1030, 1112, 1168, 1228, 1283, 1351, 1423, 1499, 1579, 1663
124
+ ],
125
+ },
126
+ h: {
127
+ mode_number: [
128
+ 17, 34, 58, 82, 106, 139, 154, 202, 235, 288, 331, 374, 427, 468, 530, 602, 674,
129
+ 331, 374, 427, 468, 530, 602, 674, 746, 813, 919,
130
+ 969, 1056, 1108, 1228, 1286, 1425, 1501, 1581, 1677, 1782,
131
+ 1897, 2022, 2157, 2301, 2361, 2524, 2625, 2735, 2927, 3057
132
+
133
+ ],
134
+ mode_alpha_numk: [
135
+ 10, 20, 35, 50, 64, 84, 93, 122, 143, 174, 200,
136
+ 200, 227, 259, 283, 321, 365, 408, 452, 493, 557,
137
+ 587, 640, 672, 744, 779, 864, 910, 958, 1016, 1080,
138
+ 1150, 1226, 1307, 1394, 1431, 1530, 1591, 1658, 1774, 1852
139
+ ],
140
+ mode_8bit_byte: [
141
+ 7, 14, 24, 34, 44, 58, 64, 84, 98, 119,
142
+ 137, 155, 177, 194, 220, 250, 280, 310, 338, 382,
143
+ 403, 439, 461, 511, 535, 593, 625, 658, 698, 742,
144
+ 790, 842, 898, 958, 983, 1051, 1093, 1139, 1219, 1273
145
+ ],
146
+ },
79
147
  }
80
148
 
81
149
 
@@ -94,7 +162,7 @@ module RQRCode #:nodoc:
94
162
  #
95
163
 
96
164
  class QRCode
97
- attr_reader :modules, :module_count, :version, :error_correction_level
165
+ attr_reader :modules, :module_count, :version
98
166
 
99
167
  # Expects a string to be parsed in, other args are optional
100
168
  #
@@ -129,11 +197,19 @@ module RQRCode #:nodoc:
129
197
  @data = string
130
198
 
131
199
  mode = QRMODE_NAME[(options[:mode] || '').to_sym]
132
- mode ||= QRAlphanumeric.valid_data?( @data ) ? :mode_alpha_numk : :mode_8bit_byte # deprecate?
200
+ # If mode is not explicitely given choose mode according to data type
201
+ mode ||= case
202
+ when RQRCode::QRNumeric.valid_data?(@data)
203
+ QRMODE_NAME[:number]
204
+ when QRAlphanumeric.valid_data?(@data)
205
+ QRMODE_NAME[:alphanumeric]
206
+ else
207
+ QRMODE_NAME[:byte_8bit]
208
+ end
133
209
 
134
210
  max_size_array = QRMAXDIGITS[level][mode]
135
211
  size = options[:size] || smallest_size_for(string, max_size_array)
136
-
212
+
137
213
  if size > QRUtil.max_size
138
214
  raise QRCodeArgumentError, "Given size greater than maximum possible size of #{QRUtil.max_size}"
139
215
  end
@@ -205,14 +281,31 @@ module RQRCode #:nodoc:
205
281
  end
206
282
  rows << cols
207
283
  end
208
-
284
+
209
285
  quiet_zone_size.times do
210
286
  rows.unshift(light * (rows.first.length / light.size))
211
287
  rows << light * (rows.first.length / light.size)
212
- end
288
+ end
213
289
  rows.join("\n")
214
290
  end
215
291
 
292
+ # Return a symbol for current error connection level
293
+ def error_correction_level
294
+ QRERRORCORRECTLEVEL.invert[@error_correct_level]
295
+ end
296
+
297
+ # Return a symbol in QRMODE.keys for current mode used
298
+ def mode
299
+ case @data_list
300
+ when QRNumeric
301
+ :mode_number
302
+ when QRAlphanumeric
303
+ :mode_alpha_numk
304
+ else
305
+ :mode_8bit_byte
306
+ end
307
+ end
308
+
216
309
  protected
217
310
 
218
311
  def make #:nodoc:
@@ -1,3 +1,3 @@
1
1
  module RQRCode
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'rqrcode'
2
+
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
 
3
3
  class RegresionTests < Minitest::Test
4
4
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require 'helper'
2
+ require 'test_helper'
3
3
 
4
4
  class QRCodeTest < Minitest::Test
5
5
  require_relative "data"
@@ -85,6 +85,24 @@ class QRCodeTest < Minitest::Test
85
85
  assert_equal "xxxxxxx xxx xxxxxxx\n", qr.to_s[0..21]
86
86
  end
87
87
 
88
+ def test_auto_numeric
89
+ # When digit only automatically uses numeric mode, default ecc level is :h
90
+ digits = RQRCode::QRCode.new('1' * 17) # Version 1, numeric mode, ECC h
91
+ assert_equal 1, digits.version
92
+ assert_equal :mode_number, digits.mode
93
+ assert_equal :h, digits.error_correction_level
94
+ # When alpha automatically works
95
+ alpha = RQRCode::QRCode.new('X' * 10) # Version 1, alpha mode, ECC h
96
+ assert_equal 1, alpha.version
97
+ assert_equal :mode_alpha_numk, alpha.mode
98
+ assert_equal :h, alpha.error_correction_level
99
+ # Generic should use binary
100
+ binary = RQRCode::QRCode.new('x' * 7) # Version 1, 8bit mode, ECC h
101
+ assert_equal 1, binary.version
102
+ assert_equal :mode_8bit_byte, binary.mode
103
+ assert_equal :h, binary.error_correction_level
104
+ end
105
+
88
106
  def test_numeric_2_M
89
107
  data = '279042272585972554922067893753871413584876543211601021503002'
90
108
 
@@ -104,6 +122,18 @@ class QRCodeTest < Minitest::Test
104
122
  end
105
123
  end
106
124
 
125
+ def test_error_correction_level
126
+ # attr_reader was wrong
127
+ assert_equal RQRCode::QRCode.new('a', level: :h).error_correction_level, :h
128
+ end
129
+
130
+ def test_version_table
131
+ # tables in RQRCode::QRCode::QRMAXDIGITS wasn't updated to support greater versions
132
+ assert_equal RQRCode::QRCode.new('1' * 289, level: :h, mode: :number).version, 11
133
+ assert_equal RQRCode::QRCode.new('A' * 175, level: :h, mode: :alphanumeric).version, 11
134
+ assert_equal RQRCode::QRCode.new('a' * 383, level: :h, mode: :byte_8bit).version, 21
135
+ end
136
+
107
137
  def test_levels
108
138
  assert RQRCode::QRCode.new("duncan", :level => :l)
109
139
  assert RQRCode::QRCode.new("duncan", :level => :m)
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
 
3
3
  describe :QRCodeExportTest do
4
4
 
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.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Blomqvist
@@ -15,42 +15,42 @@ dependencies:
15
15
  name: chunky_png
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
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
27
  version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: 1.0.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.0.0
56
56
  description: |
@@ -66,8 +66,8 @@ extra_rdoc_files:
66
66
  - CHANGELOG
67
67
  - LICENSE
68
68
  files:
69
- - ".gitignore"
70
- - ".travis.yml"
69
+ - .gitignore
70
+ - .travis.yml
71
71
  - CHANGELOG
72
72
  - Gemfile
73
73
  - LICENSE
@@ -96,7 +96,7 @@ files:
96
96
  - lib/rqrcode/version.rb
97
97
  - rqrcode.gemspec
98
98
  - test/data.rb
99
- - test/helper.rb
99
+ - test/test_helper.rb
100
100
  - test/test_regresions.rb
101
101
  - test/test_rqrcode.rb
102
102
  - test/test_rqrcode_export.rb
@@ -109,23 +109,23 @@ require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ">="
112
+ - - '>='
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ">="
117
+ - - '>='
118
118
  - !ruby/object:Gem::Version
119
119
  version: 1.3.6
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.6
122
+ rubygems_version: 2.4.8
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: A library to encode QR Codes
126
126
  test_files:
127
127
  - test/data.rb
128
- - test/helper.rb
128
+ - test/test_helper.rb
129
129
  - test/test_regresions.rb
130
130
  - test/test_rqrcode.rb
131
131
  - test/test_rqrcode_export.rb
@@ -1,9 +0,0 @@
1
- require 'rqrcode'
2
-
3
- require 'minitest/spec'
4
- require 'minitest/autorun'
5
-
6
- require 'rqrcode/export/png'
7
- require 'rqrcode/export/svg'
8
- require 'rqrcode/export/html'
9
-