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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cff0eada33f50b75d934b1f9f45e0b3675c97530
4
- data.tar.gz: ba17372851d5d9f26728d884baaea00f2d471f3b
2
+ SHA256:
3
+ metadata.gz: f4c24865c756bda423d52946750d9b685b08594946b007df49dc691cdf7812b0
4
+ data.tar.gz: 9243051860e97857a2672803af5c4aff439dc2a62bf46899700f3e921018f1ba
5
5
  SHA512:
6
- metadata.gz: 705375dedabcab27760ce69ecc0f992e668acb417d435ab3c06db189af7a8dbd9e5d6d427cdf8a863406def499e337117a36f419450d88fa9fdc58627fa0f250
7
- data.tar.gz: 2cd32bbe096b894110d9d68ec1fed83ed5289f05a6ec284ed4b25dc4d1958a1130f232a9651aa2b369e4abbbec7373520717826cbe8609e4ccf236c85eade2b3
6
+ metadata.gz: f8934e5af05802cd3cde1de57633e3066ea3ba782f6f94ad7c081f9a20ed08516d62ef669bf70136887a7eca6bafbf4f7effd40173711d83337bb62cd77c510e
7
+ data.tar.gz: 6406b4d106db3f9c1d6c8a928a2aeedf8a424f9181fa72d24e612c8f42082c4e6cd43dff601dcfa790dcfe25986fc2e18eb402166017a2ce5cb83eb51a223344
@@ -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
@@ -0,0 +1,2 @@
1
+ Performance/Casecmp:
2
+ Enabled: false
@@ -0,0 +1,9 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ inherit_from:
5
+ - ./.rubocop-common.yml # copied from c5-conventions
6
+ - ./.rubocop-performance.yml # copied from c5-conventions
7
+
8
+ AllCops:
9
+ TargetRubyVersion: 2.5
@@ -0,0 +1 @@
1
+ 2.6.6
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
2
- gemspec
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -1,22 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qr4r (0.4.0)
5
- mojo_magick
6
- rqrcode
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
- chunky_png (1.3.5)
12
- mojo_magick (0.5.6)
13
- rake (11.1.2)
14
- rqrcode (0.10.1)
15
- chunky_png (~> 1.0)
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
@@ -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 'rubygems'
2
- task :default => :test
1
+ require "rubygems"
2
+ require "rake/testtask"
3
+ task default: :test
3
4
 
4
- task 'default' => :test
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
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'qr4r'
4
- require 'optparse'
5
- require 'ostruct'
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(jpg jpeg gif tif tiff png)
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 = OptionParser.new do |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", "--format FILE_FORMAT", ALLOWED_FORMATS, "Output qrcode image format (default: gif)", " (#{ALLOWED_FORMATS.join ', '})") do |fmt|
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 |v|
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 > 0
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::encode(to_encode, outfile, cmd_options.options.marshal_dump)
85
+ Qr4r.encode(to_encode, outfile, cmd_options.options.marshal_dump)
78
86
  end
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File::expand_path(File::join(File::dirname(__FILE__), 'lib', 'qr4r'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "lib", "qr4r"))
@@ -1,52 +1,31 @@
1
- require 'rqrcode'
2
- require 'mojo_magick'
1
+ require "rqrcode_core"
2
+ require "mojo_magick"
3
3
  module Qr4r
4
-
5
- # params we use
6
- # pixel_size - size of each dot, default = 3
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] if rest && rest.length > 0
32
- opts ||= {}
33
- opts.merge!({:size => compute_size(str)}) unless opts[:size]
34
- opts.merge!({:pixel_size => 3}) unless opts[:pixel_size]
35
- qr, data = build_qr_code(str, opts)
36
- create_image(qr,data,outfile,opts)
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
- def build_qr_code(str,opts)
42
- qr = RQRCode::QRCode.new(str, opts)
43
- data = [].tap do |data|
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.dark?(x,y)
47
- 3.times { data << 0 }
25
+ if qr.checked?(x, y)
26
+ 3.times { px << 0 }
48
27
  else
49
- 3.times { data << 255 }
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(qr, data, outfile, opts)
58
- MojoMagick::convert do |c|
59
- d = data.pack 'C'*data.size
60
- c.blob(d, :format => :rgb, :depth => 8, :size => ("%dx%d" % [qr.modules.size, qr.modules.size]))
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 = qr.modules.size * opts[:pixel_size].to_i
63
- c.scale "%dx%d" % [ wd, wd ]
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 'white'
68
- c.border '%dx%d' % [ border, 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 do
79
- if slen < SIZE_RESTRICTIONS[ii]
80
- break
81
- end
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
- return ii
64
+
65
+ ii
88
66
  end
89
67
  end
90
68
  end
@@ -1,3 +1,3 @@
1
1
  module Qr4r
2
- VERSION = '0.4.1'
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -1,23 +1,28 @@
1
- $:.push File.expand_path("../lib", __FILE__)
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 = %q{QR PNG Generator for Ruby. Leveraging RQRCode and MojoMagick modules}
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('rqrcode')
21
- s.add_dependency('mojo_magick')
22
- s.add_development_dependency('rake')
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
@@ -1,124 +1,120 @@
1
- require 'test/unit'
2
- require File::expand_path(File::join(File::dirname(__FILE__), '..', 'init'))
3
- require 'tempfile'
4
- class Qr4rTest < Test::Unit::TestCase
5
-
6
- def test_encode
7
- # do something
8
- f = Tempfile.new(['qr4r','.png'])
9
- Qr4r::encode('whatever yo', f.path)
10
- # assert that it worked
11
- assert File.exists?(f.path)
12
- r = MojoMagick::get_image_size(f.path)
13
- assert r[:height] == 25 * 3
14
- assert r[:width] == 25 * 3
15
- end
16
-
17
- def test_encode_with_size
18
- # do something
19
- f = Tempfile.new(['qr4r','.png'])
20
- Qr4r::encode('whatever yo', f.path, :size => 4)
21
- # assert that it worked
22
- assert File.exists?(f)
23
- r = MojoMagick::get_image_size(f.path)
24
- assert r[:height] == 33 * 3
25
- assert r[:width] == 33 * 3
26
- end
27
-
28
- def test_encode_with_size_and_border
29
- # do something
30
- f = Tempfile.new(['qr4r','.png'])
31
- Qr4r::encode('whatever yo', f.path, :size => 4, :border => 10)
32
- # assert that it worked
33
- assert File.exists?(f)
34
- r = MojoMagick::get_image_size(f.path)
35
- assert r[:height] == 33 * 3 + 20
36
- assert r[:width] == 33 * 3 + 20
37
- end
38
-
39
- def test_encode_with_pixel_size
40
- # do something
41
- f = Tempfile.new(['qr4r','.png'])
42
- Qr4r::encode('whatever yo', f.path, :pixel_size => 5)
43
- # assert that it worked
44
- assert File.exists?(f)
45
- r = MojoMagick::get_image_size(f.path)
46
- assert r[:height] == 25 * 5
47
- assert r[:width] == 25 * 5
48
- end
49
-
50
- def test_encode_with_pixel_size_as_string
51
- # do something
52
- f = Tempfile.new(['qr4r','.png'])
53
- Qr4r::encode('whatever yo', f.path, :pixel_size => '5')
54
- # assert that it worked
55
- assert File.exists?(f)
56
- r = MojoMagick::get_image_size(f.path)
57
- assert r[:height] == 25 * 5
58
- assert r[:width] == 25 * 5
59
- end
60
-
61
- def test_encode_with_size_and_level
62
- # do something
63
- f = Tempfile.new(['qr4r','.png'])
64
- Qr4r::encode('whatever yo', f.path, :size => 4, :level => :m)
65
- # assert that it worked
66
- assert File.exists?(f)
67
- r = MojoMagick::get_image_size(f.path)
68
- assert r[:height] == 33 * 3
69
- assert r[:width] == 33 * 3
70
- end
71
-
72
- def test_a_long_string_with_size_thats_too_small
73
- caught = false
74
- begin
75
- f = Tempfile.new(['qr4r','.png'])
76
- Qr4r::encode('this string should also be encodable. don\'t ya think', f.path, :size => 4)
77
- rescue
78
- caught = true
79
- end
80
- assert caught, 'Expected an error'
81
- end
82
-
83
- def test_a_long_string_with_size_thats_right
84
- f = Tempfile.new(['qr4r','.png'])
85
- Qr4r::encode('this string should also be encodable. don\'t ya think', f.path, :size => 10)
86
- assert File.exists?(f)
87
- r = MojoMagick::get_image_size(f.path)
88
- assert r[:height] == 57 * 3
89
- assert r[:width] == 57 * 3
90
- end
91
-
92
- def test_a_long_string_without_size
93
- f = Tempfile.new(['qr4r','.png'])
94
- Qr4r::encode('this string should also be encodable. don\'t ya think', f.path)
95
- assert File.exists?(f)
96
- r = MojoMagick::get_image_size(f.path)
97
- assert r[:height] = 41 * 3
98
- assert r[:width] = 41 * 3
99
-
100
- end
101
-
102
- def test_compute_size
103
- test_sizes = [ 7, 14, 24, 34, 44, 58, 64, 84, 98]
104
- test_sizes.each_with_index do |sz, idx|
105
- str = 'a'*(sz-1)
106
- assert Qr4r.send(:compute_size, str) == idx+1
107
- str = 'a'*(sz)
108
- assert Qr4r.send(:compute_size, str) == idx+2
109
- end
110
- end
111
-
112
- def test_compute_size_too_big
113
- str = 'a'*120
114
- caught = false
115
- begin
116
- Qr4r.send(:compute_size, str)
117
- rescue Exception => ex
118
- caught = true
119
- end
120
- assert caught, "Expected exception"
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.1
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: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rqrcode
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: mojo_magick
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: '0'
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
- rubyforge_project: qr4r
95
- rubygems_version: 2.2.2
96
- signing_key:
142
+ rubygems_version: 3.0.3
143
+ signing_key:
97
144
  specification_version: 4
98
- summary: qr4r-0.4.1
145
+ summary: qr4r-0.6.0
99
146
  test_files:
100
147
  - test/qr4r_test.rb
101
- has_rdoc: