qr4r 0.3.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4c24865c756bda423d52946750d9b685b08594946b007df49dc691cdf7812b0
4
+ data.tar.gz: 9243051860e97857a2672803af5c4aff439dc2a62bf46899700f3e921018f1ba
5
+ SHA512:
6
+ metadata.gz: f8934e5af05802cd3cde1de57633e3066ea3ba782f6f94ad7c081f9a20ed08516d62ef669bf70136887a7eca6bafbf4f7effd40173711d83337bb62cd77c510e
7
+ data.tar.gz: 6406b4d106db3f9c1d6c8a928a2aeedf8a424f9181fa72d24e612c8f42082c4e6cd43dff601dcfa790dcfe25986fc2e18eb402166017a2ce5cb83eb51a223344
@@ -0,0 +1,2 @@
1
+ .bundle/
2
+ *~
@@ -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 :rubygems
2
- gemspec
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qr4r (0.6.0)
5
+ mojo_magick (~> 0.5)
6
+ rqrcode_core (~> 0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
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)
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  # QR Encoding via Ruby - with PNG output
2
2
 
3
- Leveraging [rqrcode](http://whomwah.github.com/rqrcode/) and [mojo_magick](http://github.com/2rye/mojo_magick), we've built a very thin gem that generates QR codes in a png file
3
+ Leveraging [rqrcode](http://whomwah.github.com/rqrcode/) and [mojo_magick](http://github.com/rcode5/mojo_magick), we've built a very thin gem that generates QR codes in a png file
4
4
 
5
5
  # Include in your project
6
6
 
@@ -12,6 +12,8 @@ In your code, add
12
12
 
13
13
  require 'qr4r'
14
14
 
15
+ NOTE: you'll need to have ImageMagick installed wherever you plan to run this. The gem depends on [mojo_magick](http://github.com/rcode5/mojo_magick) which uses ImageMagick commandline operations to build the final PNG image.
16
+
15
17
  To use it:
16
18
 
17
19
  Qr4r::encode(input_string, output_file_path, options)
@@ -20,7 +22,6 @@ To use it:
20
22
 
21
23
  * :pixel_size - specify the size of each 'black' dot in the qrcode. Default = 3
22
24
  * :border - specify the number of pixels to use for a white border around the outside. Default = 0
23
- * :size - used by the qr code generation. A lower number means a smaller overall image. But it also means that you can encode fewer characters. This is computeed for you by default based on the input string size. You should not need to adjust it.
24
25
 
25
26
  To encode the string 'qr codes are the new hotness' like this:
26
27
 
@@ -41,15 +42,32 @@ Add a fat border
41
42
  fname = s.gsub(/\s+/,"_") + ".qr.png"
42
43
  Qr4r::encode(s, fname, :border => 20)
43
44
 
45
+ You can also checkout the [examples](https://github.com/rcode5/qr4r/tree/master/examples) folder for a little sample commandline script.
46
+
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.
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
44
61
 
45
62
  ## Authors
46
63
 
47
- Original author: [Jon Rogers](http://github.com/bunnymatic) [at 2rye](http://2rye.com)
64
+ Original author: [Jon Rogers](http://github.com/bunnymatic) [at rcode5](http://www.rcode5.com)
48
65
 
49
66
  Thanks to [Duncan Robertson](http://whomwah.github.com/rqrcode/) for writing rQRCode
50
67
 
51
68
  ## Contributing
52
69
  * Fork the project
70
+ * Write a test for your new feature/method
53
71
  * Send a pull request
54
72
  * Don't bump the version or modify the gemspec. I'll do that when I merge in your mods and release a new version.
55
73
 
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
@@ -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::expand_path(File::join(File::dirname(__FILE__), 'lib', 'qr4r'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "lib", "qr4r"))
@@ -1,82 +1,68 @@
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
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] if rest && rest.length > 0
30
- opts = opts || {}
31
- if !opts[:size]
32
- opts.merge!({:size => compute_size(str)})
33
- end
34
- if !opts[:pixel_size]
35
- opts.merge!({:pixel_size => 3})
36
- end
37
- qr = RQRCode::QRCode.new(str, opts)
38
- data = []
39
- qr.modules.each_index do |x|
40
- qr.modules.each_index do |y|
41
- if qr.dark?(x,y)
42
- 3.times { data << 0 }
43
- else
44
- 3.times { data << 255 }
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
- MojoMagick::convert do |c|
49
- d = data.pack 'C'*data.size
50
- c.blob(d, :format => :rgb, :depth => 8, :size => ("%dx%d" % [qr.modules.size, qr.modules.size]))
51
- if opts[:pixel_size]
52
- wd = qr.modules.size * opts[:pixel_size].to_i
53
- c.scale "%dx%d" % [ wd, wd ]
54
- end
55
- if opts[:border]
56
- border = opts[:border].to_i
57
- c.bordercolor '"#ffffff"'
58
- c.border '%dx%d' % [ border, border ]
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
- private
65
- SIZE_RESTRICTIONS = [0, 7, 14, 24, 34, 44, 58, 64, 84, 98, 119]
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
- def self.compute_size(str)
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+=1
76
- end
77
- if ii > 10
78
- raise "Your string is too big for this encoder. It should be less than #{SIZE_RESTRICTIONS.last} characters"
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
@@ -1,3 +1,3 @@
1
1
  module Qr4r
2
- VERSION = '0.3.3'
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
- s.email = ["r@2rye.com"]
10
- s.homepage = "http://github.com/2rye/qr4r"
11
+ s.email = ["jon@rcode5.com"]
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,64 +1,118 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: qr4r
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Jon Rogers
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2012-03-19 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rqrcode
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
27
14
  name: mojo_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
28
21
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rqrcode_core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
35
34
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
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'
55
+ - !ruby/object:Gem::Dependency
38
56
  name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
39
63
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
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
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.93'
46
76
  type: :development
47
- version_requirements: *id003
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
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'
48
97
  description: QR PNG Generator for Ruby. Leveraging RQRCode and MojoMagick modules
49
- email:
50
- - r@2rye.com
98
+ email:
99
+ - jon@rcode5.com
51
100
  executables: []
52
-
53
101
  extensions: []
54
-
55
102
  extra_rdoc_files: []
56
-
57
- files:
58
- - .rvmrc
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop-common.yml"
106
+ - ".rubocop-performance.yml"
107
+ - ".rubocop.yml"
108
+ - ".ruby-version"
109
+ - ".rvmrc"
59
110
  - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
60
113
  - README.md
61
114
  - Rakefile
115
+ - examples/generate_qr4r.rb
62
116
  - init.rb
63
117
  - lib/qr4r.rb
64
118
  - lib/qr4r.rb~
@@ -66,32 +120,28 @@ files:
66
120
  - lib/qr4r/version.rb~
67
121
  - qr4r.gemspec
68
122
  - test/qr4r_test.rb
69
- homepage: http://github.com/2rye/qr4r
70
- licenses: []
71
-
72
- post_install_message:
123
+ homepage: http://github.com/rcode5/qr4r
124
+ licenses:
125
+ - WTFPL
126
+ metadata: {}
127
+ post_install_message:
73
128
  rdoc_options: []
74
-
75
- require_paths:
129
+ require_paths:
76
130
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
- requirements:
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
80
133
  - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
134
+ - !ruby/object:Gem::Version
135
+ version: 2.5.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
86
138
  - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
89
141
  requirements: []
90
-
91
- rubyforge_project: qr4r
92
- rubygems_version: 1.8.15
93
- signing_key:
94
- specification_version: 3
95
- summary: qr4r-0.3.3
96
- test_files:
142
+ rubygems_version: 3.0.3
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: qr4r-0.6.0
146
+ test_files:
97
147
  - test/qr4r_test.rb