rqrcode_core 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea3856aba6c1bc5602b3f7fa4126187fe26c47fdba56447b709871f96f432ff5
4
- data.tar.gz: eab7166c0e00478bcdb12ab6a550a9a9b595401bf5f6c0271c6bac95b722564f
3
+ metadata.gz: 160d94f790053a577012156c6d6dc7b5e6aa6f88766590d0494f06f9896fe89f
4
+ data.tar.gz: 2a653148523a2a04acad3abd81d62cd8d28835a43dc1dfe6821b9ab6c8c99609
5
5
  SHA512:
6
- metadata.gz: b9d1977c291eaed204644f09d3900b2ea18bde93e1c242628bdf1c4cd30573c046328e3cdbfe294c6ae27370f5963cdfa8454f1f2e6af7bf185e32cd0fefe592
7
- data.tar.gz: 56d9c31b3c056a47ffccc2848f43e0e44d3b3a984f0ef4c332505fae31dadda0ca6adac5ad0566443dbf46a86a2b81b419806cf71a9da6880d51eacd583cbb34
6
+ metadata.gz: 7b27968f77e89d07980174c98961abd1255efa317993f246161d940b53dcd185567c6710e567c6596cb1af8789fb2ee584aa2d14fdbc1b5ac3351f5552429c7d
7
+ data.tar.gz: 953c1d8de80226d141049519128c25dc345b6661b44fdc1b263c1590e4554b45cbc84a59a10c67b8c9f5e980cad0a3b8d58e5b81030532291b9d87097d96c98b
@@ -0,0 +1,4 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: whomwah
4
+ buy_me_a_coffee: duncanrobertson
@@ -3,11 +3,10 @@ name: rqrcode_core
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
7
- - release/*
8
- pull_request:
9
- branches:
10
- - master
6
+ - main
7
+ - release
8
+ pull_request: # Runs on any PR regardless of target branch
9
+ workflow_dispatch:
11
10
 
12
11
  jobs:
13
12
  Build:
@@ -15,15 +14,15 @@ jobs:
15
14
  fail-fast: false
16
15
  matrix:
17
16
  os: [ubuntu-latest, macos-latest]
18
- ruby: [2.5, 2.6, 2.7, 3.0]
17
+ ruby: ["3.0", "3.1", "3.2", "3.3", "3.4"]
19
18
  runs-on: ${{ matrix.os }}
20
19
  steps:
21
- - uses: actions/checkout@v1
22
- - uses: ruby/setup-ruby@v1
23
- with:
24
- ruby-version: ${{ matrix.ruby }}
25
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26
- - name: Run Tests
27
- run: bundle exec rake test
28
- - name: StandardRB Check
29
- run: bundle exec standardrb --format progress
20
+ - uses: actions/checkout@v3
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
+ - name: Run Tests
26
+ run: bundle exec rake test
27
+ - name: StandardRB Check
28
+ run: bundle exec standardrb --format progress
data/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0] - 2025-04-24
11
+
12
+ - Various README updates
13
+ - Fix for issue #43
14
+ - Fix for issue #42
15
+ - Drop Ruby < 3 to keep up with dependency updates
16
+ - Add option to use ENV `RQRCODE_CORE_ARCH_BITS` to override the bits value (32 or 64) used during the encoding process.
17
+ This has been shown to greatly reduce the memory usage but I can't prove it doesn't break anything for all people.
18
+ Use at your own risk.
19
+ - Fixed the 'Do Your Own Rendering' example code to reflect the current interface.
20
+
10
21
  ## [1.2.0] - 2021-08-26
11
22
 
12
23
  - Added Multi Mode Support which allows for multi-segment encoding. Thanks to [@ssayer](https://github.com/ssayer)
@@ -29,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
40
 
30
41
  ### Breaking Changes
31
42
 
32
- - Very niche but a breaking change never the less. The `to_s` method *no longer* accepts the `:true` and `:false` arguments, but prefers `:dark` and `:light`.
43
+ - Very niche but a breaking change never the less. The `to_s` method _no longer_ accepts the `:true` and `:false` arguments, but prefers `:dark` and `:light`.
33
44
 
34
45
  ## [0.2.0] - 2020-12-26
35
46
 
@@ -37,7 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
48
 
38
49
  - fix `required_ruby_version` for Ruby 3 support
39
50
 
40
- [unreleased]: https://github.com/whomwah/rqrcode_core/compare/v1.2.0...HEAD
51
+ [unreleased]: https://github.com/whomwah/rqrcode_core/compare/v2.0.0...HEAD
52
+ [2.0.0]: https://github.com/whomwah/rqrcode_core/compare/v1.2.0...2.0.0
41
53
  [1.2.0]: https://github.com/whomwah/rqrcode_core/compare/v1.1.0...v1.2.0
42
54
  [1.1.0]: https://github.com/whomwah/rqrcode_core/compare/v1.0.0...v1.1.0
43
55
  [1.0.0]: https://github.com/whomwah/rqrcode_core/compare/v0.2.0...v1.0.0
data/Gemfile.lock CHANGED
@@ -1,43 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rqrcode_core (1.2.0)
4
+ rqrcode_core (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- minitest (5.14.4)
11
- parallel (1.20.1)
12
- parser (3.0.2.0)
10
+ json (2.7.2)
11
+ language_server-protocol (3.17.0.3)
12
+ lint_roller (1.1.0)
13
+ minitest (5.25.1)
14
+ parallel (1.26.3)
15
+ parser (3.3.5.0)
13
16
  ast (~> 2.4.1)
14
- rainbow (3.0.0)
15
- rake (13.0.6)
16
- regexp_parser (2.1.1)
17
- rexml (3.2.5)
18
- rubocop (1.18.4)
17
+ racc
18
+ racc (1.8.1)
19
+ rainbow (3.1.1)
20
+ rake (13.2.1)
21
+ regexp_parser (2.9.2)
22
+ rubocop (1.66.1)
23
+ json (~> 2.3)
24
+ language_server-protocol (>= 3.17.0)
19
25
  parallel (~> 1.10)
20
- parser (>= 3.0.0.0)
26
+ parser (>= 3.3.0.2)
21
27
  rainbow (>= 2.2.2, < 4.0)
22
- regexp_parser (>= 1.8, < 3.0)
23
- rexml
24
- rubocop-ast (>= 1.8.0, < 2.0)
28
+ regexp_parser (>= 2.4, < 3.0)
29
+ rubocop-ast (>= 1.32.2, < 2.0)
25
30
  ruby-progressbar (~> 1.7)
26
- unicode-display_width (>= 1.4.0, < 3.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
- rubocop-ast (>= 0.4.0)
32
- ruby-progressbar (1.11.0)
33
- standard (1.1.7)
34
- rubocop (= 1.18.4)
35
- rubocop-performance (= 1.11.4)
36
- standardrb (1.0.0)
37
- standard
38
- unicode-display_width (2.0.0)
31
+ unicode-display_width (>= 2.4.0, < 3.0)
32
+ rubocop-ast (1.32.3)
33
+ parser (>= 3.3.1.0)
34
+ rubocop-performance (1.22.1)
35
+ rubocop (>= 1.48.1, < 2.0)
36
+ rubocop-ast (>= 1.31.1, < 2.0)
37
+ ruby-progressbar (1.13.0)
38
+ standard (1.41.0)
39
+ language_server-protocol (~> 3.17.0.2)
40
+ lint_roller (~> 1.0)
41
+ rubocop (~> 1.66.0)
42
+ standard-custom (~> 1.0.0)
43
+ standard-performance (~> 1.5)
44
+ standard-custom (1.0.2)
45
+ lint_roller (~> 1.0)
46
+ rubocop (~> 1.50)
47
+ standard-performance (1.5.0)
48
+ lint_roller (~> 1.1)
49
+ rubocop-performance (~> 1.22.0)
50
+ unicode-display_width (2.6.0)
39
51
 
40
52
  PLATFORMS
53
+ aarch64-linux
41
54
  ruby
42
55
 
43
56
  DEPENDENCIES
@@ -45,7 +58,7 @@ DEPENDENCIES
45
58
  minitest (~> 5.0)
46
59
  rake (~> 13.0)
47
60
  rqrcode_core!
48
- standardrb (~> 1.0)
61
+ standard (~> 1.41)
49
62
 
50
63
  BUNDLED WITH
51
- 2.2.22
64
+ 2.5.16
data/README.md CHANGED
@@ -7,10 +7,11 @@
7
7
 
8
8
  Features:
9
9
 
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, but also allows for encoding multiple segments.
13
- * QR Code is trademarked by Denso Wave inc.
10
+ - `rqrcode_core` is a Ruby only library. It requires no 3rd party 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, but also allows for encoding multiple segments.
13
+ - QR Code is trademarked by Denso Wave inc.
14
+ - Minimum Ruby version is `>= 3.0.0`
14
15
 
15
16
  `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
17
 
@@ -51,7 +52,11 @@ x xxx x xxxxx x xx x xxx x
51
52
 
52
53
  ```ruby
53
54
  $ require "rqrcode_core"
54
- $ qr = RQRCodeCore::QRCode.new([{data: "byteencoded", mode: :byte_8bit}, {data: "A1" * 100, mode: :alphanumeric}, {data: "1" * 500, mode: :number}])
55
+ $ qr = RQRCodeCore::QRCode.new([
56
+ {data: "byteencoded", mode: :byte_8bit},
57
+ {data: "A1" * 100, mode: :alphanumeric},
58
+ {data: "1" * 500, mode: :number}
59
+ ])
55
60
  ```
56
61
 
57
62
  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.
@@ -62,7 +67,7 @@ This will create a QR Code with byte encoded, alphanumeric and number segments.
62
67
  require "rqrcode_core"
63
68
 
64
69
  qr = RQRCodeCore::QRCode.new("https://kyan.com")
65
- qr.rows.each do |row|
70
+ qr.modules.each do |row|
66
71
  row.each do |col|
67
72
  print col ? "#" : " "
68
73
  end
@@ -92,13 +97,12 @@ mode - the mode of the QR Code (defaults to alphanumeric or byte_8bit, depending
92
97
  * :number
93
98
  * :alphanumeric
94
99
  * :byte_8bit
95
- * :kanji
96
100
  ```
97
101
 
98
102
  #### Example
99
103
 
100
104
  ```ruby
101
- RQRCodeCore::QRCode.new("http://kyan.com", size: 1, level: :m, mode: :alphanumeric)
105
+ RQRCodeCore::QRCode.new("http://kyan.com", size: 2, level: :m, mode: :byte_8bit)
102
106
  ```
103
107
 
104
108
  ## Development
@@ -128,6 +132,10 @@ $ rake standard # check
128
132
  $ rake standard:fix # fix
129
133
  ```
130
134
 
135
+ ## Experimental
136
+
137
+ On 64 bit systems when generating lots of QR Codes the lib will consume more memory than on a 32 bit systems during the internal "right shift zero fill" steps (this is expected). In tests though, it's shown that by forcing the lib to think you're on a 32 systems greatly reduces the memory footprint. This could of course have undesired consequences too! but if you're happy to try, you can use the `RQRCODE_CORE_ARCH_BITS` ENV to make this change. e.g `RQRCODE_CORE_ARCH_BITS=32`.
138
+
131
139
  ## Contributing
132
140
 
133
141
  Bug reports and pull requests are welcome on GitHub at https://github.com/whomwah/rqrcode_core.
@@ -15,12 +15,12 @@ module RQRCodeCore
15
15
 
16
16
  def get(index)
17
17
  buf_index = (index / 8).floor
18
- ((QRUtil.rszf(@buffer[buf_index], 7 - index % 8)) & 1) == 1
18
+ (QRUtil.rszf(@buffer[buf_index], 7 - index % 8) & 1) == 1
19
19
  end
20
20
 
21
21
  def put(num, length)
22
22
  (0...length).each do |i|
23
- put_bit(((QRUtil.rszf(num, length - i - 1)) & 1) == 1)
23
+ put_bit((QRUtil.rszf(num, length - i - 1) & 1) == 1)
24
24
  end
25
25
  end
26
26
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  module RQRCodeCore
4
4
  QRMODE = {
5
- mode_number: 1 << 0,
6
- mode_alpha_numk: 1 << 1,
7
- mode_8bit_byte: 1 << 2
5
+ mode_number: 1 << 0, # 1 (binary: 0001)
6
+ mode_alpha_numk: 1 << 1, # 2 (binary: 0010)
7
+ mode_8bit_byte: 1 << 2 # 4 (binary: 0100)
8
8
  }.freeze
9
9
 
10
10
  QRMODE_NAME = {
@@ -97,7 +97,6 @@ module RQRCodeCore
97
97
  # * :number
98
98
  # * :alphanumeric
99
99
  # * :byte_8bit
100
- # * :kanji
101
100
  #
102
101
  # qr = RQRCodeCore::QRCode.new('hello world', size: 1, level: :m, mode: :alphanumeric)
103
102
  # segment_qr = QRCodeCore::QRCode.new({ data: 'foo', mode: :byte_8bit })
@@ -233,14 +232,14 @@ module RQRCodeCore
233
232
 
234
233
  protected
235
234
 
236
- def make #:nodoc:
235
+ def make # :nodoc:
237
236
  prepare_common_patterns
238
237
  make_impl(false, get_best_mask_pattern)
239
238
  end
240
239
 
241
240
  private
242
241
 
243
- def prepare_common_patterns #:nodoc:
242
+ def prepare_common_patterns # :nodoc:
244
243
  @modules.map! { |row| Array.new(@module_count) }
245
244
 
246
245
  place_position_probe_pattern(0, 0)
@@ -252,7 +251,7 @@ module RQRCodeCore
252
251
  @common_patterns = @modules.map(&:clone)
253
252
  end
254
253
 
255
- def make_impl(test, mask_pattern) #:nodoc:
254
+ def make_impl(test, mask_pattern) # :nodoc:
256
255
  @modules = @common_patterns.map(&:clone)
257
256
 
258
257
  place_format_info(test, mask_pattern)
@@ -267,15 +266,15 @@ module RQRCodeCore
267
266
  map_data(@data_cache, mask_pattern)
268
267
  end
269
268
 
270
- def place_position_probe_pattern(row, col) #:nodoc:
269
+ def place_position_probe_pattern(row, col) # :nodoc:
271
270
  (-1..7).each do |r|
272
271
  next unless (row + r).between?(0, @module_count - 1)
273
272
 
274
273
  (-1..7).each do |c|
275
274
  next unless (col + c).between?(0, @module_count - 1)
276
275
 
277
- is_vert_line = (r.between?(0, 6) && (c == 0 || c == 6))
278
- is_horiz_line = (c.between?(0, 6) && (r == 0 || r == 6))
276
+ is_vert_line = r.between?(0, 6) && (c == 0 || c == 6)
277
+ is_horiz_line = c.between?(0, 6) && (r == 0 || r == 6)
279
278
  is_square = r.between?(2, 4) && c.between?(2, 4)
280
279
 
281
280
  is_part_of_probe = is_vert_line || is_horiz_line || is_square
@@ -284,11 +283,11 @@ module RQRCodeCore
284
283
  end
285
284
  end
286
285
 
287
- def get_best_mask_pattern #:nodoc:
286
+ def get_best_mask_pattern # :nodoc:
288
287
  min_lost_point = 0
289
288
  pattern = 0
290
289
 
291
- (0...8).each do |i|
290
+ 8.times do |i|
292
291
  make_impl(true, i)
293
292
  lost_point = QRUtil.get_lost_points(modules)
294
293
 
@@ -300,13 +299,13 @@ module RQRCodeCore
300
299
  pattern
301
300
  end
302
301
 
303
- def place_timing_pattern #:nodoc:
302
+ def place_timing_pattern # :nodoc:
304
303
  (8...@module_count - 8).each do |i|
305
304
  @modules[i][6] = @modules[6][i] = i % 2 == 0
306
305
  end
307
306
  end
308
307
 
309
- def place_position_adjust_pattern #:nodoc:
308
+ def place_position_adjust_pattern # :nodoc:
310
309
  positions = QRUtil.get_pattern_positions(@version)
311
310
 
312
311
  positions.each do |row|
@@ -315,7 +314,7 @@ module RQRCodeCore
315
314
 
316
315
  (-2..2).each do |r|
317
316
  (-2..2).each do |c|
318
- is_part_of_pattern = (r.abs == 2 || c.abs == 2 || (r == 0 && c == 0))
317
+ is_part_of_pattern = r.abs == 2 || c.abs == 2 || (r == 0 && c == 0)
319
318
  @modules[row + r][col + c] = is_part_of_pattern
320
319
  end
321
320
  end
@@ -323,22 +322,22 @@ module RQRCodeCore
323
322
  end
324
323
  end
325
324
 
326
- def place_version_info(test) #:nodoc:
325
+ def place_version_info(test) # :nodoc:
327
326
  bits = QRUtil.get_bch_version(@version)
328
327
 
329
- (0...18).each do |i|
330
- mod = (!test && ((bits >> i) & 1) == 1)
328
+ 18.times do |i|
329
+ mod = !test && ((bits >> i) & 1) == 1
331
330
  @modules[(i / 3).floor][ i % 3 + @module_count - 8 - 3 ] = mod
332
331
  @modules[i % 3 + @module_count - 8 - 3][ (i / 3).floor ] = mod
333
332
  end
334
333
  end
335
334
 
336
- def place_format_info(test, mask_pattern) #:nodoc:
335
+ def place_format_info(test, mask_pattern) # :nodoc:
337
336
  data = (@error_correct_level << 3 | mask_pattern)
338
337
  bits = QRUtil.get_bch_format_info(data)
339
338
 
340
339
  QRFORMATINFOLENGTH.times do |i|
341
- mod = (!test && ((bits >> i) & 1) == 1)
340
+ mod = !test && ((bits >> i) & 1) == 1
342
341
 
343
342
  # vertical
344
343
  row = if i < 6
@@ -365,7 +364,7 @@ module RQRCodeCore
365
364
  @modules[@module_count - 8][8] = !test
366
365
  end
367
366
 
368
- def map_data(data, mask_pattern) #:nodoc:
367
+ def map_data(data, mask_pattern) # :nodoc:
369
368
  inc = -1
370
369
  row = @module_count - 1
371
370
  bit_index = 7
@@ -375,7 +374,7 @@ module RQRCodeCore
375
374
  col -= 1 if col <= 6
376
375
 
377
376
  loop do
378
- (0...2).each do |c|
377
+ 2.times do |c|
379
378
  if @modules[row][col - c].nil?
380
379
  dark = false
381
380
  if byte_index < data.size && !data[byte_index].nil?
@@ -416,12 +415,12 @@ module RQRCodeCore
416
415
  minimum_version(limit: limit, version: version + 1)
417
416
  end
418
417
 
419
- def extract_options!(arr) #:nodoc:
418
+ def extract_options!(arr) # :nodoc:
420
419
  arr.last.is_a?(::Hash) ? arr.pop : {}
421
420
  end
422
421
 
423
422
  class << self
424
- def count_max_data_bits(rs_blocks) #:nodoc:
423
+ def count_max_data_bits(rs_blocks) # :nodoc:
425
424
  max_data_bytes = rs_blocks.reduce(0) do |sum, rs_block|
426
425
  sum + rs_block.data_count
427
426
  end
@@ -429,7 +428,7 @@ module RQRCodeCore
429
428
  max_data_bytes * 8
430
429
  end
431
430
 
432
- def create_data(version, error_correct_level, data_list) #:nodoc:
431
+ def create_data(version, error_correct_level, data_list) # :nodoc:
433
432
  rs_blocks = QRRSBlock.get_rs_blocks(version, error_correct_level)
434
433
  max_data_bits = QRCode.count_max_data_bits(rs_blocks)
435
434
  buffer = QRBitBuffer.new(version)
@@ -446,7 +445,7 @@ module RQRCodeCore
446
445
  QRCode.create_bytes(buffer, rs_blocks)
447
446
  end
448
447
 
449
- def create_bytes(buffer, rs_blocks) #:nodoc:
448
+ def create_bytes(buffer, rs_blocks) # :nodoc:
450
449
  offset = 0
451
450
  max_dc_count = 0
452
451
  max_ec_count = 0
@@ -473,7 +472,7 @@ module RQRCodeCore
473
472
  ecdata_block = Array.new(rs_poly.get_length - 1)
474
473
  ecdata_block.size.times do |i|
475
474
  mod_index = i + mod_poly.get_length - ecdata_block.size
476
- ecdata_block[i] = mod_index >= 0 ? mod_poly.get(mod_index) : 0
475
+ ecdata_block[i] = (mod_index >= 0) ? mod_poly.get(mod_index) : 0
477
476
  end
478
477
  ecdata[r] = ecdata_block
479
478
  end
@@ -6,7 +6,7 @@ module RQRCodeCore
6
6
  exp_table = Array.new(256)
7
7
  log_table = Array.new(256)
8
8
 
9
- (0...8).each do |i|
9
+ 8.times do |i|
10
10
  exp_table[i] = 1 << i
11
11
  end
12
12
 
@@ -17,7 +17,7 @@ module RQRCodeCore
17
17
  ^ exp_table[i - 8]
18
18
  end
19
19
 
20
- (0...255).each do |i|
20
+ 255.times do |i|
21
21
  log_table[exp_table[i]] = i
22
22
  end
23
23
 
@@ -8,7 +8,7 @@ module RQRCodeCore
8
8
  @data = data
9
9
  @mode = QRMODE_NAME.dig(mode&.to_sym)
10
10
 
11
- # If mode is not explicitely found choose mode according to data type
11
+ # If mode is not explicitly found choose mode according to data type
12
12
  @mode ||= if RQRCodeCore::QRNumeric.valid_data?(@data)
13
13
  QRMODE_NAME[:number]
14
14
  elsif QRAlphanumeric.valid_data?(@data)
@@ -36,7 +36,7 @@ module RQRCodeCore
36
36
  [1, 8, 0]
37
37
  end
38
38
 
39
- (data_length / chunk_size) * bit_length + ((data_length % chunk_size) == 0 ? 0 : extra)
39
+ (data_length / chunk_size) * bit_length + (((data_length % chunk_size) == 0) ? 0 : extra)
40
40
  end
41
41
 
42
42
  def writer
@@ -57,10 +57,17 @@ module RQRCodeCore
57
57
  BITS_FOR_MODE = {
58
58
  QRMODE[:mode_number] => [10, 12, 14],
59
59
  QRMODE[:mode_alpha_numk] => [9, 11, 13],
60
- QRMODE[:mode_8bit_byte] => [8, 16, 16],
61
- QRMODE[:mode_kanji] => [8, 10, 12]
60
+ QRMODE[:mode_8bit_byte] => [8, 16, 16]
62
61
  }.freeze
63
62
 
63
+ # This value is used during the right shift zero fill step. It is
64
+ # auto set to 32 or 64 depending on the arch of your system running.
65
+ # 64 consumes a LOT more memory. In tests it's shown changing it to 32
66
+ # on 64 bit systems greatly reduces the memory footprint. You can use
67
+ # RQRCODE_CORE_ARCH_BITS to make this change but beware it may also
68
+ # have unintended consequences so use at your own risk.
69
+ ARCH_BITS = ENV.fetch("RQRCODE_CORE_ARCH_BITS", nil)&.to_i || 1.size * 8
70
+
64
71
  def self.max_size
65
72
  PATTERN_POSITION_TABLE.count
66
73
  end
@@ -74,8 +81,8 @@ module RQRCodeCore
74
81
  end
75
82
 
76
83
  def self.rszf(num, count)
77
- # zero fill right shift
78
- (num >> count) & ((2**((num.size * 8) - count)) - 1)
84
+ # right shift zero fill
85
+ (num >> count) & ((1 << (ARCH_BITS - count)) - 1)
79
86
  end
80
87
 
81
88
  def self.get_bch_version(data)
@@ -247,7 +254,8 @@ module RQRCodeCore
247
254
  sum + col.count(true)
248
255
  end
249
256
 
250
- ratio = dark_count / (modules.size * modules.size)
257
+ # Convert to float to prevent integer division
258
+ ratio = dark_count.to_f / (modules.size * modules.size)
251
259
  ratio_delta = (100 * ratio - 50).abs / 5
252
260
 
253
261
  ratio_delta * DEMERIT_POINTS_4
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RQRCodeCore
4
- VERSION = "1.2.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/rqrcode_core.gemspec CHANGED
@@ -16,6 +16,10 @@ Gem::Specification.new do |spec|
16
16
  EOF
17
17
  spec.homepage = "https://github.com/whomwah/rqrcode_core"
18
18
  spec.license = "MIT"
19
+ spec.metadata = {
20
+ "bug_tracker_uri" => "https://github.com/whomwah/rqrcode_core/issues",
21
+ "changelog_uri" => "https://github.com/whomwah/rqrcode_core/blob/main/CHANGELOG.md"
22
+ }
19
23
 
20
24
  spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
21
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -24,9 +28,9 @@ Gem::Specification.new do |spec|
24
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
29
  spec.require_paths = ["lib"]
26
30
 
27
- spec.required_ruby_version = ">= 2.3"
31
+ spec.required_ruby_version = "~> 3.0"
28
32
  spec.add_development_dependency "bundler", "~> 2.0"
29
33
  spec.add_development_dependency "rake", "~> 13.0"
30
34
  spec.add_development_dependency "minitest", "~> 5.0"
31
- spec.add_development_dependency "standardrb", "~> 1.0"
35
+ spec.add_development_dependency "standard", "~> 1.41"
32
36
  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.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duncan Robertson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2025-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: standardrb
56
+ name: standard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '1.41'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: '1.41'
69
69
  description: |
70
70
  rqrcode_core is a Ruby library for encoding QR Codes. The simple
71
71
  interface (with no runtime dependencies) allows you to create QR Code data structures.
@@ -75,6 +75,7 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".github/FUNDING.yml"
78
79
  - ".github/workflows/ruby.yml"
79
80
  - ".gitignore"
80
81
  - CHANGELOG.md
@@ -103,24 +104,26 @@ files:
103
104
  homepage: https://github.com/whomwah/rqrcode_core
104
105
  licenses:
105
106
  - MIT
106
- metadata: {}
107
- post_install_message:
107
+ metadata:
108
+ bug_tracker_uri: https://github.com/whomwah/rqrcode_core/issues
109
+ changelog_uri: https://github.com/whomwah/rqrcode_core/blob/main/CHANGELOG.md
110
+ post_install_message:
108
111
  rdoc_options: []
109
112
  require_paths:
110
113
  - lib
111
114
  required_ruby_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
- - - ">="
116
+ - - "~>"
114
117
  - !ruby/object:Gem::Version
115
- version: '2.3'
118
+ version: '3.0'
116
119
  required_rubygems_version: !ruby/object:Gem::Requirement
117
120
  requirements:
118
121
  - - ">="
119
122
  - !ruby/object:Gem::Version
120
123
  version: '0'
121
124
  requirements: []
122
- rubygems_version: 3.2.22
123
- signing_key:
125
+ rubygems_version: 3.5.11
126
+ signing_key:
124
127
  specification_version: 4
125
128
  summary: A library to encode QR Codes
126
129
  test_files: []