qr4r 0.3.4 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +18 -0
- data/.gitignore +2 -0
- 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 +50 -0
- data/LICENSE.txt +14 -0
- data/README.md +15 -0
- data/Rakefile +10 -12
- data/examples/generate_qr4r.rb +86 -0
- data/init.rb +1 -1
- data/lib/qr4r.rb +54 -68
- data/lib/qr4r/version.rb +1 -1
- data/qr4r.gemspec +14 -9
- data/test/qr4r_test.rb +120 -124
- metadata +82 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7aa78673d39ee4d055a6fb629f57748305e9465ae6448155b8b9c7c37c30450f
|
4
|
+
data.tar.gz: 27d52de34743e9d6d5e775b97d1bfd5c15cb8e9640d60621c242fba54fed3a2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b2a47b28faf09f801b787bbedafb01da0c997a57bf1d43be8895afcf654aa2f06a5d4400662088fbbb0373029b0f977813788ee1a5ba7fce98d521a9eccfc1ad
|
7
|
+
data.tar.gz: ae6d88740bb47720ba565b2413f3a1480f0dd6c10dfe34252e30d01311d70a6f2513024d09adc4c8b1f627d64b4dcc63ffcfdda222386db8615ed8b725af5113
|
@@ -0,0 +1,18 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@1.1.2
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.6.3-stretch-node
|
9
|
+
executor: ruby/default
|
10
|
+
steps:
|
11
|
+
- checkout
|
12
|
+
- ruby/install-deps
|
13
|
+
- run:
|
14
|
+
name: Run unit tests using Rake
|
15
|
+
command: |
|
16
|
+
RAILS_ENV=test bundle exec rake test
|
17
|
+
- store_test_results:
|
18
|
+
path: test/reports
|
data/.gitignore
ADDED
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
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
qr4r (0.6.1)
|
5
|
+
mojo_magick (~> 0.6.5)
|
6
|
+
rqrcode_core (~> 0.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
minitest (5.14.4)
|
13
|
+
mojo_magick (0.6.5)
|
14
|
+
parallel (1.20.1)
|
15
|
+
parser (3.0.1.0)
|
16
|
+
ast (~> 2.4.1)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (13.0.3)
|
19
|
+
regexp_parser (2.1.1)
|
20
|
+
rexml (3.2.5)
|
21
|
+
rqrcode_core (0.2.0)
|
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 (1.4.1)
|
32
|
+
parser (>= 2.7.1.5)
|
33
|
+
rubocop-performance (1.10.2)
|
34
|
+
rubocop (>= 0.90.0, < 2.0)
|
35
|
+
rubocop-ast (>= 0.4.0)
|
36
|
+
ruby-progressbar (1.11.0)
|
37
|
+
unicode-display_width (1.7.0)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
minitest (~> 5.14)
|
44
|
+
qr4r!
|
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/README.md
CHANGED
@@ -42,8 +42,23 @@ Add a fat border
|
|
42
42
|
fname = s.gsub(/\s+/,"_") + ".qr.png"
|
43
43
|
Qr4r::encode(s, fname, :border => 20)
|
44
44
|
|
45
|
+
You can also checkout the [examples](https://github.com/rcode5/qr4r/tree/master/examples) folder for a little sample commandline script.
|
46
|
+
|
45
47
|
NOTE: The current implementation or rQRCode (and therefore this wrapper library) supports encoding up to 119 characters. Beyond that, you'll need something a bit more sophisticated.
|
46
48
|
|
49
|
+
## Wanna try it out?
|
50
|
+
|
51
|
+
Check out the Sinatra test app here: https://github.com/rcode5/qr4r_test_app
|
52
|
+
|
53
|
+
|
54
|
+
## Versions/Changelog
|
55
|
+
|
56
|
+
#### 0.4.0
|
57
|
+
|
58
|
+
* Moved to new mojo_magick gem
|
59
|
+
* no longer ruby 1.8.7 compatible
|
60
|
+
* fixed issue with border coming out black
|
61
|
+
|
47
62
|
## Authors
|
48
63
|
|
49
64
|
Original author: [Jon Rogers](http://github.com/bunnymatic) [at rcode5](http://www.rcode5.com)
|
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
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "qr4r"
|
4
|
+
require "optparse"
|
5
|
+
require "ostruct"
|
6
|
+
|
7
|
+
class CmdlineOpts
|
8
|
+
@opts = nil
|
9
|
+
|
10
|
+
ALLOWED_FORMATS = %w[jpg jpeg gif tif tiff png].freeze
|
11
|
+
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
def initialize(args)
|
15
|
+
@options = OpenStruct.new
|
16
|
+
@options.format = "gif"
|
17
|
+
@options.border = 0
|
18
|
+
@options.pixel_size = 10
|
19
|
+
@options.verbose = false
|
20
|
+
|
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|
|
29
|
+
opts.banner = "Usage: $0 [options] outfile the stuff to encode"
|
30
|
+
|
31
|
+
opts.separator ""
|
32
|
+
|
33
|
+
# Mandatory argument.
|
34
|
+
opts.on("-f",
|
35
|
+
"--format FILE_FORMAT",
|
36
|
+
ALLOWED_FORMATS,
|
37
|
+
"Output qrcode image format (default: gif)",
|
38
|
+
" (#{ALLOWED_FORMATS.join ", "})") do |fmt|
|
39
|
+
@options.format = fmt
|
40
|
+
end
|
41
|
+
opts.on("-b", "--border N",
|
42
|
+
"Render with a border of this size") do |border|
|
43
|
+
@options.border = border.to_i
|
44
|
+
end
|
45
|
+
opts.on("-p", "--pixelsize N",
|
46
|
+
"Size for each qrcode pixel") do |px|
|
47
|
+
@options.pixel_size = px.to_i
|
48
|
+
end
|
49
|
+
opts.on("-v", "--[no-]verbose", "Be verbose") do |_v|
|
50
|
+
@options.verbose = V
|
51
|
+
end
|
52
|
+
|
53
|
+
# No argument, shows at tail. This will print an options summary.
|
54
|
+
# Try it and see!
|
55
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
56
|
+
puts opts
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
opts
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/MethodLength
|
62
|
+
end
|
63
|
+
|
64
|
+
def help
|
65
|
+
puts @opts
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
cmd_options = CmdlineOpts.new(ARGV)
|
70
|
+
|
71
|
+
if ARGV.length < 2
|
72
|
+
cmd_options.help
|
73
|
+
else
|
74
|
+
outfile = ARGV.shift
|
75
|
+
to_encode = ARGV.join " "
|
76
|
+
options = cmd_options.options
|
77
|
+
|
78
|
+
if options.verbose
|
79
|
+
print "Encoding \"#{to_encode}\" to file #{outfile}"
|
80
|
+
print " with border #{options.border}" if options.border.positive?
|
81
|
+
print " and pixel_size #{options.pixel_size}"
|
82
|
+
puts " and format #{options.format}"
|
83
|
+
end
|
84
|
+
|
85
|
+
Qr4r.encode(to_encode, outfile, cmd_options.options.marshal_dump)
|
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,82 +1,68 @@
|
|
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
|
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]
|
27
7
|
|
28
8
|
def self.encode(str, outfile, *rest)
|
29
|
-
opts = rest[0]
|
30
|
-
opts
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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)
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_qr_code(str, opts)
|
21
|
+
qr = RQRCodeCore::QRCode.new(str, opts)
|
22
|
+
data = [].tap do |px|
|
23
|
+
qr.modules.each_index do |x|
|
24
|
+
qr.modules.each_index do |y|
|
25
|
+
if qr.checked?(x, y)
|
26
|
+
3.times { px << 0 }
|
27
|
+
else
|
28
|
+
3.times { px << 255 }
|
29
|
+
end
|
30
|
+
end
|
45
31
|
end
|
46
32
|
end
|
33
|
+
[qr, data]
|
47
34
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
35
|
+
|
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))
|
40
|
+
if opts[:pixel_size]
|
41
|
+
wd = qr_code.modules.size * opts[:pixel_size].to_i
|
42
|
+
c.scale format("%dx%d", wd, wd)
|
43
|
+
end
|
44
|
+
if opts[:border]
|
45
|
+
border = opts[:border].to_i
|
46
|
+
c.bordercolor "white"
|
47
|
+
c.border format("%dx%d", border, border)
|
48
|
+
end
|
49
|
+
c.file outfile
|
59
50
|
end
|
60
|
-
c.file outfile
|
61
51
|
end
|
62
|
-
end
|
63
52
|
|
64
|
-
|
65
|
-
|
53
|
+
def compute_size(str)
|
54
|
+
slen = str.size
|
55
|
+
ii = 0
|
56
|
+
while ii < SIZE_RESTRICTIONS.length
|
57
|
+
break if slen < SIZE_RESTRICTIONS[ii]
|
66
58
|
|
67
|
-
|
68
|
-
slen = str.size
|
69
|
-
size = 4
|
70
|
-
ii = 0
|
71
|
-
while ii < SIZE_RESTRICTIONS.length do
|
72
|
-
if slen < SIZE_RESTRICTIONS[ii]
|
73
|
-
break
|
59
|
+
ii += 1
|
74
60
|
end
|
75
|
-
ii
|
76
|
-
|
77
|
-
|
78
|
-
|
61
|
+
if ii > 10
|
62
|
+
raise "Your string is too big for this encoder. It should be less than #{SIZE_RESTRICTIONS.last} characters"
|
63
|
+
end
|
64
|
+
|
65
|
+
ii
|
79
66
|
end
|
80
|
-
return ii
|
81
67
|
end
|
82
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
|
-
s.email = ["
|
10
|
-
s.homepage = "http://github.com/
|
11
|
+
s.email = ["jon@rcode5.com"]
|
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.6.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,75 +1,119 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qr4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Rogers
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: mojo_magick
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 0.6.5
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 0.6.5
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: rqrcode_core
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
33
|
+
version: '0.1'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
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'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: rake
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
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
|
+
- - "~>"
|
52
74
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
75
|
+
version: '0.93'
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - "~>"
|
60
81
|
- !ruby/object:Gem::Version
|
61
|
-
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'
|
62
97
|
description: QR PNG Generator for Ruby. Leveraging RQRCode and MojoMagick modules
|
63
98
|
email:
|
64
|
-
-
|
99
|
+
- jon@rcode5.com
|
65
100
|
executables: []
|
66
101
|
extensions: []
|
67
102
|
extra_rdoc_files: []
|
68
103
|
files:
|
69
|
-
- .
|
104
|
+
- ".circleci/config.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rubocop-common.yml"
|
107
|
+
- ".rubocop-performance.yml"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".ruby-version"
|
110
|
+
- ".rvmrc"
|
70
111
|
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE.txt
|
71
114
|
- README.md
|
72
115
|
- Rakefile
|
116
|
+
- examples/generate_qr4r.rb
|
73
117
|
- init.rb
|
74
118
|
- lib/qr4r.rb
|
75
119
|
- lib/qr4r.rb~
|
@@ -77,29 +121,28 @@ files:
|
|
77
121
|
- lib/qr4r/version.rb~
|
78
122
|
- qr4r.gemspec
|
79
123
|
- test/qr4r_test.rb
|
80
|
-
homepage: http://github.com/
|
81
|
-
licenses:
|
82
|
-
|
124
|
+
homepage: http://github.com/rcode5/qr4r
|
125
|
+
licenses:
|
126
|
+
- WTFPL
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
83
129
|
rdoc_options: []
|
84
130
|
require_paths:
|
85
131
|
- lib
|
86
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
133
|
requirements:
|
89
|
-
- -
|
134
|
+
- - ">="
|
90
135
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
136
|
+
version: 2.5.0
|
92
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
138
|
requirements:
|
95
|
-
- -
|
139
|
+
- - ">="
|
96
140
|
- !ruby/object:Gem::Version
|
97
141
|
version: '0'
|
98
142
|
requirements: []
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
summary: qr4r-0.3.4
|
143
|
+
rubygems_version: 3.0.3
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: qr4r-0.6.1
|
104
147
|
test_files:
|
105
148
|
- test/qr4r_test.rb
|