qr4r 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop-common.yml +102 -0
- data/.rubocop-performance.yml +2 -0
- data/.rubocop.yml +9 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +37 -9
- data/LICENSE.txt +14 -0
- data/Rakefile +10 -12
- data/examples/generate_qr4r.rb +25 -17
- data/init.rb +1 -1
- data/lib/qr4r.rb +32 -54
- data/lib/qr4r/version.rb +1 -1
- data/qr4r.gemspec +12 -7
- data/test/qr4r_test.rb +120 -124
- metadata +71 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4c24865c756bda423d52946750d9b685b08594946b007df49dc691cdf7812b0
|
4
|
+
data.tar.gz: 9243051860e97857a2672803af5c4aff439dc2a62bf46899700f3e921018f1ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8934e5af05802cd3cde1de57633e3066ea3ba782f6f94ad7c081f9a20ed08516d62ef669bf70136887a7eca6bafbf4f7effd40173711d83337bb62cd77c510e
|
7
|
+
data.tar.gz: 6406b4d106db3f9c1d6c8a928a2aeedf8a424f9181fa72d24e612c8f42082c4e6cd43dff601dcfa790dcfe25986fc2e18eb402166017a2ce5cb83eb51a223344
|
data/.rubocop-common.yml
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
Exclude:
|
6
|
+
- "bin/*"
|
7
|
+
- "db/schema.rb"
|
8
|
+
- "lib/templates/**/*"
|
9
|
+
- "**/node_modules/**/*"
|
10
|
+
- "tmp/**/*"
|
11
|
+
- "vendor/**/*"
|
12
|
+
- "log/**/*"
|
13
|
+
|
14
|
+
Layout/CaseIndentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Layout/FirstArrayElementIndentation:
|
18
|
+
EnforcedStyle: consistent
|
19
|
+
|
20
|
+
Layout/HashAlignment:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Layout/LineLength:
|
24
|
+
Max: 120
|
25
|
+
|
26
|
+
Layout/MultilineMethodCallIndentation:
|
27
|
+
EnforcedStyle: indented
|
28
|
+
|
29
|
+
Lint/AmbiguousBlockAssociation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Lint/ScriptPermission:
|
33
|
+
Exclude:
|
34
|
+
- "Rakefile"
|
35
|
+
|
36
|
+
Metrics/AbcSize:
|
37
|
+
Max: 35
|
38
|
+
Exclude:
|
39
|
+
- "spec/**/*"
|
40
|
+
|
41
|
+
Metrics/BlockLength:
|
42
|
+
CountComments: false
|
43
|
+
Max: 50
|
44
|
+
Exclude:
|
45
|
+
- "config/**/*"
|
46
|
+
- "spec/**/*"
|
47
|
+
|
48
|
+
Metrics/ClassLength:
|
49
|
+
Max: 250
|
50
|
+
Exclude:
|
51
|
+
- "spec/**/*"
|
52
|
+
|
53
|
+
Metrics/MethodLength:
|
54
|
+
Max: 25
|
55
|
+
Exclude:
|
56
|
+
- "db/migrate/*"
|
57
|
+
- "spec/**/*"
|
58
|
+
|
59
|
+
Naming/PredicateName:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Security/YAMLLoad:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/BarePercentLiterals:
|
66
|
+
EnforcedStyle: percent_q
|
67
|
+
|
68
|
+
Style/BlockDelimiters:
|
69
|
+
EnforcedStyle: braces_for_chaining
|
70
|
+
|
71
|
+
Style/Documentation:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Style/EmptyMethod:
|
75
|
+
EnforcedStyle: expanded
|
76
|
+
|
77
|
+
Style/FormatStringToken:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Style/FrozenStringLiteralComment:
|
81
|
+
EnforcedStyle: never
|
82
|
+
|
83
|
+
Style/Lambda:
|
84
|
+
EnforcedStyle: literal
|
85
|
+
|
86
|
+
Style/ModuleFunction:
|
87
|
+
EnforcedStyle: extend_self
|
88
|
+
|
89
|
+
Style/MutableConstant:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/PreferredHashMethods:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/StringLiterals:
|
96
|
+
EnforcedStyle: double_quotes
|
97
|
+
|
98
|
+
Style/StringLiteralsInInterpolation:
|
99
|
+
EnforcedStyle: double_quotes
|
100
|
+
|
101
|
+
Style/TernaryParentheses:
|
102
|
+
EnforcedStyle: require_parentheses_when_complex
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
2
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,50 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qr4r (0.
|
5
|
-
mojo_magick
|
6
|
-
|
4
|
+
qr4r (0.6.0)
|
5
|
+
mojo_magick (~> 0.5)
|
6
|
+
rqrcode_core (~> 0.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
ast (2.4.1)
|
12
|
+
minitest (5.14.1)
|
13
|
+
mojo_magick (0.5.7)
|
14
|
+
parallel (1.19.2)
|
15
|
+
parser (2.7.2.0)
|
16
|
+
ast (~> 2.4.1)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (13.0.1)
|
19
|
+
regexp_parser (1.8.2)
|
20
|
+
rexml (3.2.4)
|
21
|
+
rqrcode_core (0.1.2)
|
22
|
+
rubocop (0.93.1)
|
23
|
+
parallel (~> 1.10)
|
24
|
+
parser (>= 2.7.1.5)
|
25
|
+
rainbow (>= 2.2.2, < 4.0)
|
26
|
+
regexp_parser (>= 1.8)
|
27
|
+
rexml
|
28
|
+
rubocop-ast (>= 0.6.0)
|
29
|
+
ruby-progressbar (~> 1.7)
|
30
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
31
|
+
rubocop-ast (0.8.0)
|
32
|
+
parser (>= 2.7.1.5)
|
33
|
+
rubocop-performance (1.8.1)
|
34
|
+
rubocop (>= 0.87.0)
|
35
|
+
rubocop-ast (>= 0.4.0)
|
36
|
+
ruby-progressbar (1.10.1)
|
37
|
+
unicode-display_width (1.7.0)
|
16
38
|
|
17
39
|
PLATFORMS
|
18
40
|
ruby
|
19
41
|
|
20
42
|
DEPENDENCIES
|
43
|
+
minitest (~> 5.14)
|
21
44
|
qr4r!
|
22
|
-
rake
|
45
|
+
rake (~> 13.0)
|
46
|
+
rubocop (~> 0.93)
|
47
|
+
rubocop-performance (~> 1.8)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (C) 2020 Jon Rogers <jon@rcode5.com>
|
5
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
6
|
+
|
7
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
8
|
+
copies of this license document, and changing it is allowed as long
|
9
|
+
as the name is changed.
|
10
|
+
|
11
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
12
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
13
|
+
|
14
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/Rakefile
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "rake/testtask"
|
3
|
+
task default: :test
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
desc "Default: run tests"
|
7
|
-
task :test do
|
8
|
-
require 'rake/runtest'
|
9
|
-
files = Dir.glob(File.join(File.dirname(__FILE__), 'test/*_test.rb'))
|
10
|
-
files.each do |f|
|
11
|
-
Rake.run_tests f
|
12
|
-
end
|
5
|
+
Rake::TestTask.new do |task|
|
6
|
+
task.pattern = "test/*_test.rb"
|
13
7
|
end
|
14
8
|
|
15
9
|
task :build do
|
16
10
|
`rm qr4r-*.gem`
|
17
|
-
puts `gem build qr4r.gemspec`
|
11
|
+
puts `gem build qr4r.gemspec`
|
12
|
+
end
|
13
|
+
|
14
|
+
task release: :build do
|
15
|
+
puts `gem push qr4r-*.gem`
|
18
16
|
end
|
data/examples/generate_qr4r.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "qr4r"
|
4
|
+
require "optparse"
|
5
|
+
require "ostruct"
|
6
6
|
|
7
7
|
class CmdlineOpts
|
8
|
-
|
9
8
|
@opts = nil
|
10
9
|
|
11
|
-
ALLOWED_FORMATS = %w
|
10
|
+
ALLOWED_FORMATS = %w[jpg jpeg gif tif tiff png].freeze
|
12
11
|
|
13
12
|
attr_reader :options
|
14
13
|
|
@@ -19,13 +18,24 @@ class CmdlineOpts
|
|
19
18
|
@options.pixel_size = 10
|
20
19
|
@options.verbose = false
|
21
20
|
|
22
|
-
@opts =
|
21
|
+
@opts = setup_options
|
22
|
+
|
23
|
+
@opts.parse!(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
27
|
+
def setup_options
|
28
|
+
OptionParser.new do |opts|
|
23
29
|
opts.banner = "Usage: $0 [options] outfile the stuff to encode"
|
24
30
|
|
25
31
|
opts.separator ""
|
26
32
|
|
27
33
|
# Mandatory argument.
|
28
|
-
opts.on("-f",
|
34
|
+
opts.on("-f",
|
35
|
+
"--format FILE_FORMAT",
|
36
|
+
ALLOWED_FORMATS,
|
37
|
+
"Output qrcode image format (default: gif)",
|
38
|
+
" (#{ALLOWED_FORMATS.join ", "})") do |fmt|
|
29
39
|
@options.format = fmt
|
30
40
|
end
|
31
41
|
opts.on("-b", "--border N",
|
@@ -36,7 +46,7 @@ class CmdlineOpts
|
|
36
46
|
"Size for each qrcode pixel") do |px|
|
37
47
|
@options.pixel_size = px.to_i
|
38
48
|
end
|
39
|
-
opts.on("-v", "--[no-]verbose", "Be verbose") do |
|
49
|
+
opts.on("-v", "--[no-]verbose", "Be verbose") do |_v|
|
40
50
|
@options.verbose = V
|
41
51
|
end
|
42
52
|
|
@@ -46,17 +56,15 @@ class CmdlineOpts
|
|
46
56
|
puts opts
|
47
57
|
exit
|
48
58
|
end
|
59
|
+
opts
|
49
60
|
end
|
61
|
+
# rubocop:enable Metrics/MethodLength
|
62
|
+
end
|
50
63
|
|
51
|
-
@opts.parse!(args)
|
52
|
-
|
53
|
-
end # parse()
|
54
|
-
|
55
64
|
def help
|
56
65
|
puts @opts
|
57
66
|
end
|
58
|
-
|
59
|
-
end
|
67
|
+
end
|
60
68
|
|
61
69
|
cmd_options = CmdlineOpts.new(ARGV)
|
62
70
|
|
@@ -64,15 +72,15 @@ if ARGV.length < 2
|
|
64
72
|
cmd_options.help
|
65
73
|
else
|
66
74
|
outfile = ARGV.shift
|
67
|
-
to_encode = ARGV.join
|
75
|
+
to_encode = ARGV.join " "
|
68
76
|
options = cmd_options.options
|
69
77
|
|
70
78
|
if options.verbose
|
71
79
|
print "Encoding \"#{to_encode}\" to file #{outfile}"
|
72
|
-
print " with border #{options.border}" if options.border
|
80
|
+
print " with border #{options.border}" if options.border.positive?
|
73
81
|
print " and pixel_size #{options.pixel_size}"
|
74
82
|
puts " and format #{options.format}"
|
75
83
|
end
|
76
84
|
|
77
|
-
Qr4r
|
85
|
+
Qr4r.encode(to_encode, outfile, cmd_options.options.marshal_dump)
|
78
86
|
end
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "lib", "qr4r"))
|
data/lib/qr4r.rb
CHANGED
@@ -1,52 +1,31 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rqrcode_core"
|
2
|
+
require "mojo_magick"
|
3
3
|
module Qr4r
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
# params we pass to QRCode include :size and :level
|
8
|
-
# size - the size of the qrcode (default 4)
|
9
|
-
# level - the error correction level, can be:
|
10
|
-
# * Level :l 7% of code can be restored
|
11
|
-
# * Level :m 15% of code can be restored
|
12
|
-
# * Level :q 25% of code can be restored
|
13
|
-
# * Level :h 30% of code can be restored
|
14
|
-
# note: if size is not included and 4 appears to be too small for the included string, we'll make it bigger
|
15
|
-
# if you include size, we'll use it, which may lead to an error if the string is too long
|
16
|
-
# Limitations are as follows:
|
17
|
-
# size = 1, max string length = 7
|
18
|
-
# size = 2, max string length = 14
|
19
|
-
# size = 3, max string length = 24
|
20
|
-
# size = 4, max string length = 34
|
21
|
-
# size = 5, max string length = 44
|
22
|
-
# size = 6, max string length = 58
|
23
|
-
# size = 7, max string length = 64
|
24
|
-
# size = 8, max string length = 84
|
25
|
-
# size = 9, max string length = 98
|
26
|
-
# size = 10, max string length = 119
|
27
|
-
|
28
|
-
SIZE_RESTRICTIONS = [0, 7, 14, 24, 34, 44, 58, 64, 84, 98, 119]
|
4
|
+
# These come from rqrcode_core - read https://github.com/whomwah/rqrcode_core
|
5
|
+
# for more information
|
6
|
+
SIZE_RESTRICTIONS = [0, 7, 14, 24, 34, 44, 58, 64, 84, 98, 119]
|
29
7
|
|
30
8
|
def self.encode(str, outfile, *rest)
|
31
|
-
opts = rest[0]
|
32
|
-
opts ||= {}
|
33
|
-
opts
|
34
|
-
opts
|
35
|
-
|
36
|
-
create_image(
|
9
|
+
opts = rest[0] unless rest.empty?
|
10
|
+
opts ||= {}
|
11
|
+
opts[:size] = compute_size(str) unless opts[:size]
|
12
|
+
opts[:pixel_size] = 3 unless opts[:pixel_size]
|
13
|
+
qr_code, data = build_qr_code(str, opts)
|
14
|
+
create_image(qr_code, data, outfile, opts)
|
37
15
|
end
|
38
16
|
|
39
17
|
class << self
|
40
18
|
private
|
41
|
-
|
42
|
-
|
43
|
-
|
19
|
+
|
20
|
+
def build_qr_code(str, opts)
|
21
|
+
qr = RQRCodeCore::QRCode.new(str, opts)
|
22
|
+
data = [].tap do |px|
|
44
23
|
qr.modules.each_index do |x|
|
45
24
|
qr.modules.each_index do |y|
|
46
|
-
if qr.
|
47
|
-
3.times {
|
25
|
+
if qr.checked?(x, y)
|
26
|
+
3.times { px << 0 }
|
48
27
|
else
|
49
|
-
3.times {
|
28
|
+
3.times { px << 255 }
|
50
29
|
end
|
51
30
|
end
|
52
31
|
end
|
@@ -54,37 +33,36 @@ module Qr4r
|
|
54
33
|
[qr, data]
|
55
34
|
end
|
56
35
|
|
57
|
-
def create_image(
|
58
|
-
MojoMagick
|
59
|
-
d = data.pack
|
60
|
-
c.blob(d, :
|
36
|
+
def create_image(qr_code, data, outfile, opts)
|
37
|
+
MojoMagick.convert do |c|
|
38
|
+
d = data.pack "C" * data.size
|
39
|
+
c.blob(d, format: :rgb, depth: 8, size: format("%dx%d", qr_code.modules.size, qr_code.modules.size))
|
61
40
|
if opts[:pixel_size]
|
62
|
-
wd =
|
63
|
-
c.scale "%dx%d"
|
41
|
+
wd = qr_code.modules.size * opts[:pixel_size].to_i
|
42
|
+
c.scale format("%dx%d", wd, wd)
|
64
43
|
end
|
65
44
|
if opts[:border]
|
66
45
|
border = opts[:border].to_i
|
67
|
-
c.bordercolor
|
68
|
-
c.border
|
46
|
+
c.bordercolor "white"
|
47
|
+
c.border format("%dx%d", border, border)
|
69
48
|
end
|
70
49
|
c.file outfile
|
71
50
|
end
|
72
51
|
end
|
73
52
|
|
74
|
-
|
75
53
|
def compute_size(str)
|
76
54
|
slen = str.size
|
77
55
|
ii = 0
|
78
|
-
while ii < SIZE_RESTRICTIONS.length
|
79
|
-
if slen < SIZE_RESTRICTIONS[ii]
|
80
|
-
|
81
|
-
|
82
|
-
ii+=1
|
56
|
+
while ii < SIZE_RESTRICTIONS.length
|
57
|
+
break if slen < SIZE_RESTRICTIONS[ii]
|
58
|
+
|
59
|
+
ii += 1
|
83
60
|
end
|
84
61
|
if ii > 10
|
85
62
|
raise "Your string is too big for this encoder. It should be less than #{SIZE_RESTRICTIONS.last} characters"
|
86
63
|
end
|
87
|
-
|
64
|
+
|
65
|
+
ii
|
88
66
|
end
|
89
67
|
end
|
90
68
|
end
|
data/lib/qr4r/version.rb
CHANGED
data/qr4r.gemspec
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
2
|
require "qr4r/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
+
s.required_ruby_version = ">= 2.5.0"
|
5
6
|
s.name = "qr4r"
|
7
|
+
s.licenses = ['WTFPL']
|
6
8
|
s.version = Qr4r::VERSION
|
7
9
|
s.platform = Gem::Platform::RUBY
|
8
10
|
s.authors = ["Jon Rogers"]
|
9
11
|
s.email = ["jon@rcode5.com"]
|
10
12
|
s.homepage = "http://github.com/rcode5/qr4r"
|
11
13
|
s.summary = "qr4r-#{Qr4r::VERSION}"
|
12
|
-
s.description =
|
14
|
+
s.description = "QR PNG Generator for Ruby. Leveraging RQRCode and MojoMagick modules"
|
13
15
|
|
14
16
|
s.rubyforge_project = "qr4r"
|
15
|
-
|
17
|
+
|
16
18
|
s.files = `git ls-files`.split("\n")
|
17
19
|
s.test_files = `git ls-files -- {test,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
21
|
s.require_paths = ["lib"]
|
20
|
-
s.add_dependency('
|
21
|
-
s.add_dependency('
|
22
|
-
s.add_development_dependency(
|
22
|
+
s.add_dependency("mojo_magick", '~> 0.5')
|
23
|
+
s.add_dependency("rqrcode_core", '~> 0.1')
|
24
|
+
s.add_development_dependency("minitest", "~> 5.14")
|
25
|
+
s.add_development_dependency("rake", "~> 13.0")
|
26
|
+
s.add_development_dependency("rubocop", "~> 0.93")
|
27
|
+
s.add_development_dependency("rubocop-performance", "~> 1.8")
|
23
28
|
end
|
data/test/qr4r_test.rb
CHANGED
@@ -1,124 +1,120 @@
|
|
1
|
-
require
|
2
|
-
require File
|
3
|
-
require
|
4
|
-
class Qr4rTest < Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
r
|
13
|
-
assert r[:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
r
|
24
|
-
assert r[:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
r
|
35
|
-
assert r[:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
r
|
46
|
-
assert r[:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
r
|
57
|
-
assert r[:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
r
|
68
|
-
assert r[:
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
r
|
88
|
-
assert r[:
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
r =
|
97
|
-
assert r[:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
str =
|
106
|
-
assert Qr4r.send(:compute_size, str) == idx+
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
1
|
+
require "minitest/autorun"
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
|
3
|
+
require "tempfile"
|
4
|
+
class Qr4rTest < MiniTest::Test
|
5
|
+
def test_encode
|
6
|
+
# do something
|
7
|
+
f = Tempfile.new(["qr4r", ".png"])
|
8
|
+
Qr4r.encode("whatever yo", f.path)
|
9
|
+
# assert that it worked
|
10
|
+
assert File.exist?(f.path)
|
11
|
+
r = MojoMagick.get_image_size(f.path)
|
12
|
+
assert r[:height] == 25 * 3
|
13
|
+
assert r[:width] == 25 * 3
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_encode_with_size
|
17
|
+
# do something
|
18
|
+
f = Tempfile.new(["qr4r", ".png"])
|
19
|
+
Qr4r.encode("whatever yo", f.path, size: 4)
|
20
|
+
# assert that it worked
|
21
|
+
assert File.exist?(f)
|
22
|
+
r = MojoMagick.get_image_size(f.path)
|
23
|
+
assert r[:height] == 33 * 3
|
24
|
+
assert r[:width] == 33 * 3
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_encode_with_size_and_border
|
28
|
+
# do something
|
29
|
+
f = Tempfile.new(["qr4r", ".png"])
|
30
|
+
Qr4r.encode("whatever yo", f.path, size: 4, border: 10)
|
31
|
+
# assert that it worked
|
32
|
+
assert File.exist?(f)
|
33
|
+
r = MojoMagick.get_image_size(f.path)
|
34
|
+
assert r[:height] == 33 * 3 + 20
|
35
|
+
assert r[:width] == 33 * 3 + 20
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_encode_with_pixel_size
|
39
|
+
# do something
|
40
|
+
f = Tempfile.new(["qr4r", ".png"])
|
41
|
+
Qr4r.encode("whatever yo", f.path, pixel_size: 5)
|
42
|
+
# assert that it worked
|
43
|
+
assert File.exist?(f)
|
44
|
+
r = MojoMagick.get_image_size(f.path)
|
45
|
+
assert r[:height] == 25 * 5
|
46
|
+
assert r[:width] == 25 * 5
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_encode_with_pixel_size_as_string
|
50
|
+
# do something
|
51
|
+
f = Tempfile.new(["qr4r", ".png"])
|
52
|
+
Qr4r.encode("whatever yo", f.path, pixel_size: "5")
|
53
|
+
# assert that it worked
|
54
|
+
assert File.exist?(f)
|
55
|
+
r = MojoMagick.get_image_size(f.path)
|
56
|
+
assert r[:height] == 25 * 5
|
57
|
+
assert r[:width] == 25 * 5
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_encode_with_size_and_level
|
61
|
+
# do something
|
62
|
+
f = Tempfile.new(["qr4r", ".png"])
|
63
|
+
Qr4r.encode("whatever yo", f.path, size: 4, level: :m)
|
64
|
+
# assert that it worked
|
65
|
+
assert File.exist?(f)
|
66
|
+
r = MojoMagick.get_image_size(f.path)
|
67
|
+
assert r[:height] == 33 * 3
|
68
|
+
assert r[:width] == 33 * 3
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_a_long_string_with_size_thats_too_small
|
72
|
+
caught = false
|
73
|
+
begin
|
74
|
+
f = Tempfile.new(["qr4r", ".png"])
|
75
|
+
Qr4r.encode("this string should also be encodable. don't ya think", f.path, size: 4)
|
76
|
+
rescue StandardError
|
77
|
+
caught = true
|
78
|
+
end
|
79
|
+
assert caught, "Expected an error"
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_a_long_string_with_size_thats_right
|
83
|
+
f = Tempfile.new(["qr4r", ".png"])
|
84
|
+
Qr4r.encode("this string should also be encodable. don't ya think", f.path, size: 10)
|
85
|
+
assert File.exist?(f)
|
86
|
+
r = MojoMagick.get_image_size(f.path)
|
87
|
+
assert r[:height] == 57 * 3
|
88
|
+
assert r[:width] == 57 * 3
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_a_long_string_without_size
|
92
|
+
f = Tempfile.new(["qr4r", ".png"])
|
93
|
+
Qr4r.encode("this string should also be encodable. don't ya think", f.path)
|
94
|
+
assert File.exist?(f)
|
95
|
+
r = MojoMagick.get_image_size(f.path)
|
96
|
+
assert r[:height] = 41 * 3
|
97
|
+
assert r[:width] = 41 * 3
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_compute_size
|
101
|
+
test_sizes = [7, 14, 24, 34, 44, 58, 64, 84, 98]
|
102
|
+
test_sizes.each_with_index do |sz, idx|
|
103
|
+
str = "a" * (sz - 1)
|
104
|
+
assert Qr4r.send(:compute_size, str) == idx + 1
|
105
|
+
str = "a" * sz
|
106
|
+
assert Qr4r.send(:compute_size, str) == idx + 2
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_compute_size_too_big
|
111
|
+
str = "a" * 120
|
112
|
+
caught = false
|
113
|
+
begin
|
114
|
+
Qr4r.send(:compute_size, str)
|
115
|
+
rescue StandardError => _e
|
116
|
+
caught = true
|
117
|
+
end
|
118
|
+
assert caught, "Expected exception"
|
119
|
+
end
|
120
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qr4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rogers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: mojo_magick
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rqrcode_core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.14'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
75
|
+
version: '0.93'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
82
|
+
version: '0.93'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
55
97
|
description: QR PNG Generator for Ruby. Leveraging RQRCode and MojoMagick modules
|
56
98
|
email:
|
57
99
|
- jon@rcode5.com
|
@@ -60,9 +102,14 @@ extensions: []
|
|
60
102
|
extra_rdoc_files: []
|
61
103
|
files:
|
62
104
|
- ".gitignore"
|
105
|
+
- ".rubocop-common.yml"
|
106
|
+
- ".rubocop-performance.yml"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".ruby-version"
|
63
109
|
- ".rvmrc"
|
64
110
|
- Gemfile
|
65
111
|
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
66
113
|
- README.md
|
67
114
|
- Rakefile
|
68
115
|
- examples/generate_qr4r.rb
|
@@ -74,9 +121,10 @@ files:
|
|
74
121
|
- qr4r.gemspec
|
75
122
|
- test/qr4r_test.rb
|
76
123
|
homepage: http://github.com/rcode5/qr4r
|
77
|
-
licenses:
|
124
|
+
licenses:
|
125
|
+
- WTFPL
|
78
126
|
metadata: {}
|
79
|
-
post_install_message:
|
127
|
+
post_install_message:
|
80
128
|
rdoc_options: []
|
81
129
|
require_paths:
|
82
130
|
- lib
|
@@ -84,18 +132,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
132
|
requirements:
|
85
133
|
- - ">="
|
86
134
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
135
|
+
version: 2.5.0
|
88
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
137
|
requirements:
|
90
138
|
- - ">="
|
91
139
|
- !ruby/object:Gem::Version
|
92
140
|
version: '0'
|
93
141
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
signing_key:
|
142
|
+
rubygems_version: 3.0.3
|
143
|
+
signing_key:
|
97
144
|
specification_version: 4
|
98
|
-
summary: qr4r-0.
|
145
|
+
summary: qr4r-0.6.0
|
99
146
|
test_files:
|
100
147
|
- test/qr4r_test.rb
|
101
|
-
has_rdoc:
|