rqrcode_core 1.1.0 → 1.2.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
  SHA256:
3
- metadata.gz: bc2b513b4aa28453c231e4fa52d53c4406bf03bbba9df84ab87eed0e22193389
4
- data.tar.gz: fc7b7bfc2ad40315031899501b94a1b2a35c8987b6eeff9cd9c71d77b4e5d3d4
3
+ metadata.gz: ea3856aba6c1bc5602b3f7fa4126187fe26c47fdba56447b709871f96f432ff5
4
+ data.tar.gz: eab7166c0e00478bcdb12ab6a550a9a9b595401bf5f6c0271c6bac95b722564f
5
5
  SHA512:
6
- metadata.gz: de4b6fdb7ab8f356fb55aedbc93fb949f51f1f68acebdc1aa7d4b82ecf90cf785065104bbf68170ea39f20671ff513c5eb212cbbdb42f38f099f133612d70d17
7
- data.tar.gz: 0a2e8ea5a6e0a2bf43a9d94a3333cc95d6558f47f6369dd5a07107e12079db85b8a21dec57ef31920a855648c96e630fc68d40942e3f9e4570a6f2f07b4c1ee5
6
+ metadata.gz: b9d1977c291eaed204644f09d3900b2ea18bde93e1c242628bdf1c4cd30573c046328e3cdbfe294c6ae27370f5963cdfa8454f1f2e6af7bf185e32cd0fefe592
7
+ data.tar.gz: 56d9c31b3c056a47ffccc2848f43e0e44d3b3a984f0ef4c332505fae31dadda0ca6adac5ad0566443dbf46a86a2b81b419806cf71a9da6880d51eacd583cbb34
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.0] - 2021-08-26
11
+
12
+ - Added Multi Mode Support which allows for multi-segment encoding. Thanks to [@ssayer](https://github.com/ssayer)
13
+
10
14
  ## [1.1.0] - 2021-07-01
11
15
 
12
16
  - Add a basic benchmark file
@@ -33,7 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
37
 
34
38
  - fix `required_ruby_version` for Ruby 3 support
35
39
 
36
- [unreleased]: https://github.com/whomwah/rqrcode_core/compare/v1.1.0...HEAD
40
+ [unreleased]: https://github.com/whomwah/rqrcode_core/compare/v1.2.0...HEAD
41
+ [1.2.0]: https://github.com/whomwah/rqrcode_core/compare/v1.1.0...v1.2.0
37
42
  [1.1.0]: https://github.com/whomwah/rqrcode_core/compare/v1.0.0...v1.1.0
38
43
  [1.0.0]: https://github.com/whomwah/rqrcode_core/compare/v0.2.0...v1.0.0
39
44
  [0.2.0]: https://github.com/whomwah/rqrcode_core/compare/v0.1.2...v0.2.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rqrcode_core (1.1.0)
4
+ rqrcode_core (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,30 +9,30 @@ GEM
9
9
  ast (2.4.2)
10
10
  minitest (5.14.4)
11
11
  parallel (1.20.1)
12
- parser (3.0.1.0)
12
+ parser (3.0.2.0)
13
13
  ast (~> 2.4.1)
14
14
  rainbow (3.0.0)
15
- rake (13.0.3)
15
+ rake (13.0.6)
16
16
  regexp_parser (2.1.1)
17
17
  rexml (3.2.5)
18
- rubocop (1.12.1)
18
+ rubocop (1.18.4)
19
19
  parallel (~> 1.10)
20
20
  parser (>= 3.0.0.0)
21
21
  rainbow (>= 2.2.2, < 4.0)
22
22
  regexp_parser (>= 1.8, < 3.0)
23
23
  rexml
24
- rubocop-ast (>= 1.2.0, < 2.0)
24
+ rubocop-ast (>= 1.8.0, < 2.0)
25
25
  ruby-progressbar (~> 1.7)
26
26
  unicode-display_width (>= 1.4.0, < 3.0)
27
- rubocop-ast (1.4.1)
28
- parser (>= 2.7.1.5)
29
- rubocop-performance (1.10.1)
30
- rubocop (>= 0.90.0, < 2.0)
27
+ rubocop-ast (1.9.1)
28
+ parser (>= 3.0.1.1)
29
+ rubocop-performance (1.11.4)
30
+ rubocop (>= 1.7.0, < 2.0)
31
31
  rubocop-ast (>= 0.4.0)
32
32
  ruby-progressbar (1.11.0)
33
- standard (1.0.5)
34
- rubocop (= 1.12.1)
35
- rubocop-performance (= 1.10.1)
33
+ standard (1.1.7)
34
+ rubocop (= 1.18.4)
35
+ rubocop-performance (= 1.11.4)
36
36
  standardrb (1.0.0)
37
37
  standard
38
38
  unicode-display_width (2.0.0)
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  standardrb (~> 1.0)
49
49
 
50
50
  BUNDLED WITH
51
- 2.2.15
51
+ 2.2.22
data/README.md CHANGED
@@ -3,16 +3,16 @@
3
3
 
4
4
  # RQRCodeCore
5
5
 
6
- `rqrcode_core` is a library for encoding QR codes in pure Ruby. It has a simple interface with all the standard qrcode options. It was originally adapted in 2008 from a Javascript library by [Kazuhiko Arase](https://github.com/kazuhikoarase).
6
+ `rqrcode_core` is a library for encoding QR Codes in pure Ruby. It has a simple interface with all the standard qrcode options. It was originally adapted in 2008 from a Javascript library by [Kazuhiko Arase](https://github.com/kazuhikoarase).
7
7
 
8
8
  Features:
9
9
 
10
10
  * `rqrcode_core` is a Ruby only library. It requires no native libraries. Just Ruby!
11
- * It is an encoding library. You can't decode QR codes with it.
12
- * The interface is simple and assumes you just want to encode a string into a QR code.
13
- * QR code is trademarked by Denso Wave inc.
11
+ * It is an encoding library. You can't decode QR Codes with it.
12
+ * The interface is simple and assumes you just want to encode a string into a QR Code, but also allows for encoding multiple segments.
13
+ * QR Code is trademarked by Denso Wave inc.
14
14
 
15
- `rqrcode_core` is the basis of the popular `rqrcode` gem [https://github.com/whomwah/rqrcode]. This gem allows you to generate different renderings of your QR code, including `png`, `svg` and `ansi`.
15
+ `rqrcode_core` is the basis of the popular `rqrcode` gem [https://github.com/whomwah/rqrcode]. This gem allows you to generate different renderings of your QR Code, including `png`, `svg` and `ansi`.
16
16
 
17
17
  ## Installation
18
18
 
@@ -47,6 +47,15 @@ x xxx x xxxxx x xx x xxx x
47
47
  ... etc
48
48
  ```
49
49
 
50
+ ## Multiple Encoding Support
51
+
52
+ ```ruby
53
+ $ require "rqrcode_core"
54
+ $ qr = RQRCodeCore::QRCode.new([{data: "byteencoded", mode: :byte_8bit}, {data: "A1" * 100, mode: :alphanumeric}, {data: "1" * 500, mode: :number}])
55
+ ```
56
+
57
+ This will create a QR Code with byte encoded, alphanumeric and number segments. Any combination of encodings/segments will work provided it fits within size limits.
58
+
50
59
  ## Doing your own rendering
51
60
 
52
61
  ```ruby
@@ -64,12 +73,14 @@ end
64
73
 
65
74
  ### Options
66
75
 
67
- The library expects a string to be parsed in, other args are optional.
76
+ The library expects a string or array (for multiple encodings) to be parsed in, other args are optional.
68
77
 
69
78
  ```
70
- string - the string you wish to encode
79
+ data - the string or array you wish to encode
80
+
81
+ size - the size (integer) of the QR Code (defaults to smallest size needed to encode the string)
71
82
 
72
- size - the size (integer) of the qrcode (defaults to smallest size needed to encode the string)
83
+ max_size - the max_size (Integer) of the QR Code (default RQRCodeCore::QRUtil.max_size)
73
84
 
74
85
  level - the error correction level, can be:
75
86
  * Level :l 7% of code can be restored
@@ -77,7 +88,7 @@ level - the error correction level, can be:
77
88
  * Level :q 25% of code can be restored
78
89
  * Level :h 30% of code can be restored (default :h)
79
90
 
80
- mode - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data):
91
+ mode - the mode of the QR Code (defaults to alphanumeric or byte_8bit, depending on the input data, only used when data is a string):
81
92
  * :number
82
93
  * :alphanumeric
83
94
  * :byte_8bit
@@ -10,7 +10,8 @@ module RQRCodeCore
10
10
  QRMODE_NAME = {
11
11
  number: :mode_number,
12
12
  alphanumeric: :mode_alpha_numk,
13
- byte_8bit: :mode_8bit_byte
13
+ byte_8bit: :mode_8bit_byte,
14
+ multi: :mode_multi
14
15
  }.freeze
15
16
 
16
17
  QRERRORCORRECTLEVEL = {
@@ -49,89 +50,19 @@ module RQRCodeCore
49
50
  # http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable2-e.html
50
51
  # http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable3-e.html
51
52
  # http://web.archive.org/web/20110710094955/http://www.denso-wave.com/qrcode/vertable4-e.html
52
- # Each array contains levels max chars from level 1 to level 40
53
- QRMAXDIGITS = {
54
- l: {
55
- mode_number: [
56
- 41, 77, 127, 187, 255, 322, 370, 461, 552, 652, 772,
57
- 883, 1022, 1101, 1250, 1408, 1548, 1725, 1903, 2061,
58
- 2232, 2409, 2620, 2812, 3057, 3283, 3514, 3669, 3909, 4158,
59
- 4417, 4686, 4965, 5253, 5529, 5836, 6153, 6479, 6743, 7089
60
- ],
61
- mode_alpha_numk: [
62
- 25, 47, 77, 114, 154, 195, 224, 279, 335, 395,
63
- 468, 535, 619, 667, 758, 854, 938, 1046, 1153, 1249,
64
- 1352, 1460, 1588, 1704, 1853, 1990, 2132, 2223, 2369, 2520,
65
- 2677, 2840, 3009, 3183, 3351, 3537, 3729, 3927, 4087, 4296
66
- ],
67
- mode_8bit_byte: [
68
- 17, 32, 53, 78, 106, 134, 154, 192, 230, 271,
69
- 321, 367, 425, 458, 520, 586, 644, 718, 792, 858,
70
- 929, 1003, 1091, 1171, 1273, 1367, 1465, 1528, 1628, 1732,
71
- 1840, 1952, 2068, 2188, 2303, 2431, 2563, 2699, 2809, 2953
72
- ]
73
- },
74
- m: {
75
- mode_number: [
76
- 34, 63, 101, 149, 202, 255, 293, 365, 432, 513,
77
- 604, 691, 796, 871, 991, 1082, 1212, 1346, 1500, 1600,
78
- 1708, 1872, 2059, 2188, 2395, 2544, 2701, 2857, 3035, 3289,
79
- 3486, 3693, 3909, 4134, 4343, 4588, 4775, 5039, 5313, 5596
80
- ],
81
- mode_alpha_numk: [
82
- 20, 38, 61, 90, 122, 154, 178, 221, 262, 311,
83
- 366, 419, 483, 528, 600, 656, 734, 816, 909, 970,
84
- 1035, 1134, 1248, 1326, 1451, 1542, 1637, 1732, 1839, 1994,
85
- 2113, 2238, 2369, 2506, 2632, 2780, 2894, 3054, 3220, 3391
86
- ],
87
- mode_8bit_byte: [
88
- 14, 26, 42, 62, 84, 106, 122, 152, 180, 213,
89
- 251, 287, 331, 362, 412, 450, 504, 560, 624, 666,
90
- 711, 779, 857, 911, 997, 1059, 1125, 1190, 1264, 1370,
91
- 1452, 1538, 1628, 1722, 1809, 1911, 1989, 2099, 2213, 2331
92
- ]
93
- },
94
- q: {
95
- mode_number: [
96
- 27, 48, 77, 111, 144, 178, 207, 259, 312, 364,
97
- 427, 489, 580, 621, 703, 775, 876, 948, 1063, 1159,
98
- 1224, 1358, 1468, 1588, 1718, 1804, 1933, 2085, 2181, 2358,
99
- 2473, 2670, 2805, 2949, 3081, 3244, 3417, 3599, 3791, 3993
100
- ],
101
- mode_alpha_numk: [
102
- 16, 29, 47, 67, 87, 108, 125, 157, 189, 221,
103
- 259, 296, 352, 376, 426, 470, 531, 574, 644, 702,
104
- 742, 823, 890, 963, 1041, 1094, 1172, 1263, 1322, 1429,
105
- 1499, 1618, 1700, 1787, 1867, 1966, 2071, 2181, 2298, 2420
106
- ],
107
- mode_8bit_byte: [
108
- 11, 20, 32, 46, 60, 74, 86, 108, 130, 151,
109
- 177, 203, 241, 258, 292, 22, 364, 394, 442, 482,
110
- 509, 565, 611, 661, 715, 751, 805, 868, 908, 982,
111
- 1030, 1112, 1168, 1228, 1283, 1351, 1423, 1499, 1579, 1663
112
- ]
113
- },
114
- h: {
115
- mode_number: [
116
- 17, 34, 58, 82, 106, 139, 154, 202, 235, 288, 331, 374, 427, 468, 530, 602, 674,
117
- 331, 374, 427, 468, 530, 602, 674, 746, 813, 919,
118
- 969, 1056, 1108, 1228, 1286, 1425, 1501, 1581, 1677, 1782,
119
- 1897, 2022, 2157, 2301, 2361, 2524, 2625, 2735, 2927, 3057
120
-
121
- ],
122
- mode_alpha_numk: [
123
- 10, 20, 35, 50, 64, 84, 93, 122, 143, 174, 200,
124
- 200, 227, 259, 283, 321, 365, 408, 452, 493, 557,
125
- 587, 640, 672, 744, 779, 864, 910, 958, 1016, 1080,
126
- 1150, 1226, 1307, 1394, 1431, 1530, 1591, 1658, 1774, 1852
127
- ],
128
- mode_8bit_byte: [
129
- 7, 14, 24, 34, 44, 58, 64, 84, 98, 119,
130
- 137, 155, 177, 194, 220, 250, 280, 310, 338, 382,
131
- 403, 439, 461, 511, 535, 593, 625, 658, 698, 742,
132
- 790, 842, 898, 958, 983, 1051, 1093, 1139, 1219, 1273
133
- ]
134
- }
53
+ QRMAXBITS = {
54
+ l: [152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192, 2592, 2960, 3424, 3688, 4184,
55
+ 4712, 5176, 5768, 6360, 6888, 7456, 8048, 8752, 9392, 10_208, 10_960, 11_744, 12_248,
56
+ 13_048, 13_880, 14_744, 15_640, 16_568, 17_528, 18_448, 19_472, 20_528, 21_616, 22_496, 23_648],
57
+ m: [128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728, 2032, 2320, 2672, 2920, 3320, 3624,
58
+ 4056, 4504, 5016, 5352, 5712, 6256, 6880, 7312, 8000, 8496, 9024, 9544, 10_136, 10_984,
59
+ 11_640, 12_328, 13_048, 13_800, 14_496, 15_312, 15_936, 16_816, 17_728, 18_672],
60
+ q: [104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936,
61
+ 3176, 3560, 3880, 4096, 4544, 4912, 5312, 5744, 6032, 6464, 6968, 7288, 7880, 8264, 8920, 9368,
62
+ 9848, 10288, 10832, 11408, 12016, 12656, 13328],
63
+ h: [72, 128, 208, 288, 368, 480, 528, 688, 800, 976, 1120, 1264, 1440, 1576, 1784,
64
+ 2024, 2264, 2504, 2728, 3080, 3248, 3536, 3712, 4112, 4304, 4768, 5024, 5288, 5608, 5960,
65
+ 6344, 6760, 7208, 7688, 7888, 8432, 8768, 9136, 9776, 10_208]
135
66
  }.freeze
136
67
 
137
68
  # StandardErrors
@@ -152,69 +83,59 @@ module RQRCodeCore
152
83
  class QRCode
153
84
  attr_reader :modules, :module_count, :version
154
85
 
155
- # Expects a string to be parsed in, other args are optional
86
+ # Expects a string or array (for multi-segment encoding) to be parsed in, other args are optional
156
87
  #
157
- # # string - the string you wish to encode
158
- # # size - the size (Integer) of the qrcode (defaults to smallest size needed to encode the string)
159
- # # level - the error correction level, can be:
88
+ # # data - the string, QRSegment or array of Hashes (with data:, mode: keys) you wish to encode
89
+ # # size - the size (Integer) of the QR Code (defaults to smallest size needed to encode the data)
90
+ # # max_size - the max_size (Integer) of the QR Code (default RQRCodeCore::QRUtil.max_size)
91
+ # # level - the error correction level, can be:
160
92
  # * Level :l 7% of code can be restored
161
93
  # * Level :m 15% of code can be restored
162
94
  # * Level :q 25% of code can be restored
163
95
  # * Level :h 30% of code can be restored (default :h)
164
- # # mode - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data):
96
+ # # mode - the mode of the QR Code (defaults to alphanumeric or byte_8bit, depending on the input data, only used when data is a string):
165
97
  # * :number
166
98
  # * :alphanumeric
167
99
  # * :byte_8bit
168
100
  # * :kanji
169
101
  #
170
102
  # qr = RQRCodeCore::QRCode.new('hello world', size: 1, level: :m, mode: :alphanumeric)
171
- #
172
-
173
- def initialize(string, *args)
174
- if !string.is_a? String
175
- raise QRCodeArgumentError, "The passed data is #{string.class}, not String"
176
- end
103
+ # segment_qr = QRCodeCore::QRCode.new({ data: 'foo', mode: :byte_8bit })
104
+ # multi_qr = RQRCodeCore::QRCode.new([{ data: 'foo', mode: :byte_8bit }, { data: 'bar1', mode: :alphanumeric }])
177
105
 
106
+ def initialize(data, *args)
178
107
  options = extract_options!(args)
179
- level = (options[:level] || :h).to_sym
180
108
 
181
- if !QRERRORCORRECTLEVEL.has_key?(level)
182
- raise QRCodeArgumentError, "Unknown error correction level `#{level.inspect}`"
109
+ level = (options[:level] || :h).to_sym
110
+ max_size = options[:max_size] || QRUtil.max_size
111
+
112
+ @data = case data
113
+ when String
114
+ QRSegment.new(data: data, mode: options[:mode])
115
+ when Array
116
+ raise QRCodeArgumentError, "Array must contain Hashes with :data and :mode keys" unless data.all? { |seg| seg.is_a?(Hash) && %i[data mode].all? { |s| seg.key? s } }
117
+ data.map { |seg| QRSegment.new(**seg) }
118
+ when QRSegment
119
+ data
120
+ else
121
+ raise QRCodeArgumentError, "data must be a String, QRSegment, or an Array"
183
122
  end
123
+ @error_correct_level = QRERRORCORRECTLEVEL[level]
184
124
 
185
- @data = string
186
-
187
- mode = QRMODE_NAME[(options[:mode] || "").to_sym]
188
- # If mode is not explicitely given choose mode according to data type
189
- mode ||= if RQRCodeCore::QRNumeric.valid_data?(@data)
190
- QRMODE_NAME[:number]
191
- elsif QRAlphanumeric.valid_data?(@data)
192
- QRMODE_NAME[:alphanumeric]
193
- else
194
- QRMODE_NAME[:byte_8bit]
125
+ unless @error_correct_level
126
+ raise QRCodeArgumentError, "Unknown error correction level `#{level.inspect}`"
195
127
  end
196
128
 
197
- max_size_array = QRMAXDIGITS[level][mode]
198
- size = options[:size] || smallest_size_for(string, max_size_array)
129
+ size = options[:size] || minimum_version(limit: max_size)
199
130
 
200
- if size > QRUtil.max_size
131
+ if size > max_size
201
132
  raise QRCodeArgumentError, "Given size greater than maximum possible size of #{QRUtil.max_size}"
202
133
  end
203
134
 
204
- @error_correct_level = QRERRORCORRECTLEVEL[level]
205
135
  @version = size
206
136
  @module_count = @version * 4 + QRPOSITIONPATTERNLENGTH
207
137
  @modules = Array.new(@module_count)
208
- @data_list =
209
- case mode
210
- when :mode_number
211
- QRNumeric.new(@data)
212
- when :mode_alpha_numk
213
- QRAlphanumeric.new(@data)
214
- else
215
- QR8bitByte.new(@data)
216
- end
217
-
138
+ @data_list = multi_segment? ? QRMulti.new(@data) : @data.writer
218
139
  @data_cache = nil
219
140
  make
220
141
  end
@@ -293,6 +214,11 @@ module RQRCodeCore
293
214
  QRERRORCORRECTLEVEL.invert[@error_correct_level]
294
215
  end
295
216
 
217
+ # Return true if this QR Code includes multiple encoded segments
218
+ def multi_segment?
219
+ @data.is_a?(Array)
220
+ end
221
+
296
222
  # Return a symbol in QRMODE.keys for current mode used
297
223
  def mode
298
224
  case @data_list
@@ -478,11 +404,16 @@ module RQRCodeCore
478
404
  end
479
405
  end
480
406
 
481
- def smallest_size_for(string, max_size_array) #:nodoc:
482
- l = string.bytesize
483
- ver = max_size_array.index { |i| i >= l }
484
- raise QRCodeRunTimeError, "code length overflow. (#{l} digits > any version capacity)" unless ver
485
- ver + 1
407
+ def minimum_version(limit: QRUtil.max_size, version: 1)
408
+ raise QRCodeRunTimeError, "Data length exceed maximum capacity of version #{limit}" if version > limit
409
+
410
+ max_size_bits = QRMAXBITS[error_correction_level][version - 1]
411
+
412
+ size_bits = multi_segment? ? @data.sum { |seg| seg.size(version) } : @data.size(version)
413
+
414
+ return version if size_bits < max_size_bits
415
+
416
+ minimum_version(limit: limit, version: version + 1)
486
417
  end
487
418
 
488
419
  def extract_options!(arr) #:nodoc:
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RQRCodeCore
4
+ class QRMulti
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ def write(buffer)
10
+ @data.each { |seg| seg.writer.write(buffer) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RQRCodeCore
4
+ class QRSegment
5
+ attr_reader :data, :mode
6
+
7
+ def initialize(data:, mode: nil)
8
+ @data = data
9
+ @mode = QRMODE_NAME.dig(mode&.to_sym)
10
+
11
+ # If mode is not explicitely found choose mode according to data type
12
+ @mode ||= if RQRCodeCore::QRNumeric.valid_data?(@data)
13
+ QRMODE_NAME[:number]
14
+ elsif QRAlphanumeric.valid_data?(@data)
15
+ QRMODE_NAME[:alphanumeric]
16
+ else
17
+ QRMODE_NAME[:byte_8bit]
18
+ end
19
+ end
20
+
21
+ def size(version)
22
+ 4 + header_size(version) + content_size
23
+ end
24
+
25
+ def header_size(version)
26
+ QRUtil.get_length_in_bits(QRMODE[mode], version)
27
+ end
28
+
29
+ def content_size
30
+ chunk_size, bit_length, extra = case mode
31
+ when :mode_number
32
+ [3, QRNumeric::NUMBER_LENGTH[3], QRNumeric::NUMBER_LENGTH[data_length % 3] || 0]
33
+ when :mode_alpha_numk
34
+ [2, 11, 6]
35
+ when :mode_8bit_byte
36
+ [1, 8, 0]
37
+ end
38
+
39
+ (data_length / chunk_size) * bit_length + ((data_length % chunk_size) == 0 ? 0 : extra)
40
+ end
41
+
42
+ def writer
43
+ case mode
44
+ when :mode_number
45
+ QRNumeric.new(data)
46
+ when :mode_alpha_numk
47
+ QRAlphanumeric.new(data)
48
+ when :mode_multi
49
+ QRMulti.new(data)
50
+ else
51
+ QR8bitByte.new(data)
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def data_length
58
+ data.bytesize
59
+ end
60
+ end
61
+ end
@@ -5,7 +5,9 @@ require "rqrcode_core/qrcode/qr_alphanumeric"
5
5
  require "rqrcode_core/qrcode/qr_bit_buffer"
6
6
  require "rqrcode_core/qrcode/qr_code"
7
7
  require "rqrcode_core/qrcode/qr_math"
8
+ require "rqrcode_core/qrcode/qr_multi"
8
9
  require "rqrcode_core/qrcode/qr_numeric"
9
10
  require "rqrcode_core/qrcode/qr_polynomial"
10
11
  require "rqrcode_core/qrcode/qr_rs_block"
12
+ require "rqrcode_core/qrcode/qr_segment"
11
13
  require "rqrcode_core/qrcode/qr_util"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RQRCodeCore
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duncan Robertson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-01 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,9 +92,11 @@ files:
92
92
  - lib/rqrcode_core/qrcode/qr_bit_buffer.rb
93
93
  - lib/rqrcode_core/qrcode/qr_code.rb
94
94
  - lib/rqrcode_core/qrcode/qr_math.rb
95
+ - lib/rqrcode_core/qrcode/qr_multi.rb
95
96
  - lib/rqrcode_core/qrcode/qr_numeric.rb
96
97
  - lib/rqrcode_core/qrcode/qr_polynomial.rb
97
98
  - lib/rqrcode_core/qrcode/qr_rs_block.rb
99
+ - lib/rqrcode_core/qrcode/qr_segment.rb
98
100
  - lib/rqrcode_core/qrcode/qr_util.rb
99
101
  - lib/rqrcode_core/version.rb
100
102
  - rqrcode_core.gemspec
@@ -117,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  - !ruby/object:Gem::Version
118
120
  version: '0'
119
121
  requirements: []
120
- rubygems_version: 3.2.15
122
+ rubygems_version: 3.2.22
121
123
  signing_key:
122
124
  specification_version: 4
123
125
  summary: A library to encode QR Codes