rqrcode_core 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/Rakefile +5 -0
- data/lib/rqrcode_core/qrcode/qr_8bit_byte.rb +2 -8
- data/lib/rqrcode_core/qrcode/qr_alphanumeric.rb +11 -16
- data/lib/rqrcode_core/qrcode/qr_bit_buffer.rb +2 -2
- data/lib/rqrcode_core/qrcode/qr_code.rb +8 -8
- data/lib/rqrcode_core/qrcode/qr_math.rb +2 -2
- data/lib/rqrcode_core/qrcode/qr_numeric.rb +4 -15
- data/lib/rqrcode_core/qrcode/qr_rs_block.rb +2 -2
- data/lib/rqrcode_core/qrcode/qr_util.rb +2 -2
- data/lib/rqrcode_core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc2b513b4aa28453c231e4fa52d53c4406bf03bbba9df84ab87eed0e22193389
|
4
|
+
data.tar.gz: fc7b7bfc2ad40315031899501b94a1b2a35c8987b6eeff9cd9c71d77b4e5d3d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de4b6fdb7ab8f356fb55aedbc93fb949f51f1f68acebdc1aa7d4b82ecf90cf785065104bbf68170ea39f20671ff513c5eb212cbbdb42f38f099f133612d70d17
|
7
|
+
data.tar.gz: 0a2e8ea5a6e0a2bf43a9d94a3333cc95d6558f47f6369dd5a07107e12079db85b8a21dec57ef31920a855648c96e630fc68d40942e3f9e4570a6f2f07b4c1ee5
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [1.1.0] - 2021-07-01
|
11
|
+
|
12
|
+
- Add a basic benchmark file
|
13
|
+
- Add standardRB badge
|
14
|
+
- Add `.freeze` on `CONST` lookup objects
|
15
|
+
- Remove unused `@mode` instance variable
|
16
|
+
- A batch of small refactors and optimizations
|
17
|
+
|
10
18
|
## [1.0.0] - 2021-04-23
|
11
19
|
|
12
20
|
### Changed
|
@@ -25,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
25
33
|
|
26
34
|
- fix `required_ruby_version` for Ruby 3 support
|
27
35
|
|
28
|
-
[unreleased]: https://github.com/whomwah/rqrcode_core/compare/v1.
|
36
|
+
[unreleased]: https://github.com/whomwah/rqrcode_core/compare/v1.1.0...HEAD
|
37
|
+
[1.1.0]: https://github.com/whomwah/rqrcode_core/compare/v1.0.0...v1.1.0
|
29
38
|
[1.0.0]: https://github.com/whomwah/rqrcode_core/compare/v0.2.0...v1.0.0
|
30
39
|
[0.2.0]: https://github.com/whomwah/rqrcode_core/compare/v0.1.2...v0.2.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
![](https://github.com/whomwah/rqrcode_core/actions/workflows/ruby.yml/badge.svg)
|
2
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
2
3
|
|
3
4
|
# RQRCodeCore
|
4
5
|
|
@@ -6,7 +7,7 @@
|
|
6
7
|
|
7
8
|
Features:
|
8
9
|
|
9
|
-
* `rqrcode_core` is a
|
10
|
+
* `rqrcode_core` is a Ruby only library. It requires no native libraries. Just Ruby!
|
10
11
|
* It is an encoding library. You can't decode QR codes with it.
|
11
12
|
* The interface is simple and assumes you just want to encode a string into a QR code.
|
12
13
|
* QR code is trademarked by Denso Wave inc.
|
data/Rakefile
CHANGED
@@ -2,19 +2,13 @@
|
|
2
2
|
|
3
3
|
module RQRCodeCore
|
4
4
|
class QR8bitByte
|
5
|
-
attr_reader :mode
|
6
|
-
|
7
5
|
def initialize(data)
|
8
|
-
@mode = QRMODE[:mode_8bit_byte]
|
9
6
|
@data = data
|
10
7
|
end
|
11
8
|
|
12
|
-
def get_length
|
13
|
-
@data.bytesize
|
14
|
-
end
|
15
|
-
|
16
9
|
def write(buffer)
|
17
|
-
buffer.byte_encoding_start(
|
10
|
+
buffer.byte_encoding_start(@data.bytesize)
|
11
|
+
|
18
12
|
@data.each_byte do |b|
|
19
13
|
buffer.put(b, 8)
|
20
14
|
end
|
@@ -1,32 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RQRCodeCore
|
4
|
-
ALPHANUMERIC = [
|
4
|
+
ALPHANUMERIC = [
|
5
|
+
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
|
6
|
+
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ", "$",
|
7
|
+
"%", "*", "+", "-", ".", "/", ":"
|
8
|
+
].freeze
|
5
9
|
|
6
10
|
class QRAlphanumeric
|
7
|
-
attr_reader :mode
|
8
|
-
|
9
11
|
def initialize(data)
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
unless QRAlphanumeric.valid_data?(data)
|
13
|
+
raise QRCodeArgumentError, "Not a alpha numeric uppercase string `#{data}`"
|
14
|
+
end
|
13
15
|
|
14
16
|
@data = data
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.valid_data? data
|
22
|
-
data.each_char do |s|
|
23
|
-
return false if ALPHANUMERIC.index(s).nil?
|
24
|
-
end
|
25
|
-
true
|
19
|
+
def self.valid_data?(data)
|
20
|
+
(data.chars - ALPHANUMERIC).empty?
|
26
21
|
end
|
27
22
|
|
28
23
|
def write(buffer)
|
29
|
-
buffer.alphanumeric_encoding_start(
|
24
|
+
buffer.alphanumeric_encoding_start(@data.size)
|
30
25
|
|
31
26
|
@data.size.times do |i|
|
32
27
|
if i % 2 == 0
|
@@ -64,8 +64,8 @@ module RQRCodeCore
|
|
64
64
|
|
65
65
|
# Pad with padding code words
|
66
66
|
while get_length_in_bits < prefered_size
|
67
|
-
put(
|
68
|
-
put(
|
67
|
+
put(PAD0, 8)
|
68
|
+
put(PAD1, 8) if get_length_in_bits < prefered_size
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -5,20 +5,20 @@ module RQRCodeCore
|
|
5
5
|
mode_number: 1 << 0,
|
6
6
|
mode_alpha_numk: 1 << 1,
|
7
7
|
mode_8bit_byte: 1 << 2
|
8
|
-
}
|
8
|
+
}.freeze
|
9
9
|
|
10
10
|
QRMODE_NAME = {
|
11
11
|
number: :mode_number,
|
12
12
|
alphanumeric: :mode_alpha_numk,
|
13
13
|
byte_8bit: :mode_8bit_byte
|
14
|
-
}
|
14
|
+
}.freeze
|
15
15
|
|
16
16
|
QRERRORCORRECTLEVEL = {
|
17
17
|
l: 1,
|
18
18
|
m: 0,
|
19
19
|
q: 3,
|
20
20
|
h: 2
|
21
|
-
}
|
21
|
+
}.freeze
|
22
22
|
|
23
23
|
QRMASKPATTERN = {
|
24
24
|
pattern000: 0,
|
@@ -29,7 +29,7 @@ module RQRCodeCore
|
|
29
29
|
pattern101: 5,
|
30
30
|
pattern110: 6,
|
31
31
|
pattern111: 7
|
32
|
-
}
|
32
|
+
}.freeze
|
33
33
|
|
34
34
|
QRMASKCOMPUTATIONS = [
|
35
35
|
proc { |i, j| (i + j) % 2 == 0 },
|
@@ -40,7 +40,7 @@ module RQRCodeCore
|
|
40
40
|
proc { |i, j| (i * j) % 2 + (i * j) % 3 == 0 },
|
41
41
|
proc { |i, j| ((i * j) % 2 + (i * j) % 3) % 2 == 0 },
|
42
42
|
proc { |i, j| ((i * j) % 3 + (i + j) % 2) % 2 == 0 }
|
43
|
-
]
|
43
|
+
].freeze
|
44
44
|
|
45
45
|
QRPOSITIONPATTERNLENGTH = (7 + 1) * 2 + 1
|
46
46
|
QRFORMATINFOLENGTH = 15
|
@@ -132,7 +132,7 @@ module RQRCodeCore
|
|
132
132
|
790, 842, 898, 958, 983, 1051, 1093, 1139, 1219, 1273
|
133
133
|
]
|
134
134
|
}
|
135
|
-
}
|
135
|
+
}.freeze
|
136
136
|
|
137
137
|
# StandardErrors
|
138
138
|
|
@@ -314,7 +314,7 @@ module RQRCodeCore
|
|
314
314
|
|
315
315
|
private
|
316
316
|
|
317
|
-
def prepare_common_patterns
|
317
|
+
def prepare_common_patterns #:nodoc:
|
318
318
|
@modules.map! { |row| Array.new(@module_count) }
|
319
319
|
|
320
320
|
place_position_probe_pattern(0, 0)
|
@@ -490,7 +490,7 @@ module RQRCodeCore
|
|
490
490
|
end
|
491
491
|
|
492
492
|
class << self
|
493
|
-
def count_max_data_bits(rs_blocks)
|
493
|
+
def count_max_data_bits(rs_blocks) #:nodoc:
|
494
494
|
max_data_bytes = rs_blocks.reduce(0) do |sum, rs_block|
|
495
495
|
sum + rs_block.data_count
|
496
496
|
end
|
@@ -1,32 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RQRCodeCore
|
4
|
-
NUMERIC = [
|
4
|
+
NUMERIC = %w[0 1 2 3 4 5 6 7 8 9].freeze
|
5
5
|
|
6
6
|
class QRNumeric
|
7
|
-
attr_reader :mode
|
8
|
-
|
9
7
|
def initialize(data)
|
10
|
-
@mode = QRMODE[:mode_number]
|
11
|
-
|
12
8
|
raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)
|
13
9
|
|
14
10
|
@data = data
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
18
|
-
|
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
|
13
|
+
def self.valid_data?(data)
|
14
|
+
(data.chars - NUMERIC).empty?
|
26
15
|
end
|
27
16
|
|
28
17
|
def write(buffer)
|
29
|
-
buffer.numeric_encoding_start(
|
18
|
+
buffer.numeric_encoding_start(@data.size)
|
30
19
|
|
31
20
|
@data.size.times do |i|
|
32
21
|
if i % 3 == 0
|
@@ -10,7 +10,7 @@ module RQRCodeCore
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# http://www.thonky.com/qr-code-tutorial/error-correction-table/
|
13
|
-
|
13
|
+
RS_BLOCK_TABLE = [
|
14
14
|
# L
|
15
15
|
# M
|
16
16
|
# Q
|
@@ -256,7 +256,7 @@ module RQRCodeCore
|
|
256
256
|
[34, 54, 24, 34, 55, 25],
|
257
257
|
[20, 45, 15, 61, 46, 16]
|
258
258
|
|
259
|
-
]
|
259
|
+
].freeze
|
260
260
|
|
261
261
|
def self.get_rs_blocks(version, error_correct_level)
|
262
262
|
rs_block = QRRSBlock.get_rs_block_table(version, error_correct_level)
|
@@ -43,7 +43,7 @@ module RQRCodeCore
|
|
43
43
|
[6, 32, 58, 84, 110, 136, 162],
|
44
44
|
[6, 26, 54, 82, 110, 138, 166],
|
45
45
|
[6, 30, 58, 86, 114, 142, 170]
|
46
|
-
]
|
46
|
+
].freeze
|
47
47
|
|
48
48
|
G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0
|
49
49
|
G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0
|
@@ -59,7 +59,7 @@ module RQRCodeCore
|
|
59
59
|
QRMODE[:mode_alpha_numk] => [9, 11, 13],
|
60
60
|
QRMODE[:mode_8bit_byte] => [8, 16, 16],
|
61
61
|
QRMODE[:mode_kanji] => [8, 10, 12]
|
62
|
-
}
|
62
|
+
}.freeze
|
63
63
|
|
64
64
|
def self.max_size
|
65
65
|
PATTERN_POSITION_TABLE.count
|
data/lib/rqrcode_core/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|