rqrcode 0.10.1 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +13 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +108 -136
  6. data/Rakefile +10 -0
  7. data/_config.yml +1 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/images/ansi-screen-shot.png +0 -0
  11. data/images/github-qrcode.png +0 -0
  12. data/images/github-qrcode.svg +32 -0
  13. data/lib/rqrcode.rb +8 -19
  14. data/lib/rqrcode/export.rb +6 -0
  15. data/lib/rqrcode/export/ansi.rb +14 -15
  16. data/lib/rqrcode/export/html.rb +6 -8
  17. data/lib/rqrcode/export/png.rb +18 -19
  18. data/lib/rqrcode/export/svg.rb +7 -6
  19. data/lib/rqrcode/qrcode.rb +3 -4
  20. data/lib/rqrcode/qrcode/qrcode.rb +17 -0
  21. data/lib/rqrcode/version.rb +3 -1
  22. data/rqrcode.gemspec +36 -0
  23. metadata +67 -56
  24. data/CHANGELOG +0 -97
  25. data/LICENSE +0 -19
  26. data/lib/rqrcode/core_ext.rb +0 -5
  27. data/lib/rqrcode/core_ext/array.rb +0 -5
  28. data/lib/rqrcode/core_ext/array/behavior.rb +0 -12
  29. data/lib/rqrcode/core_ext/integer.rb +0 -5
  30. data/lib/rqrcode/core_ext/integer/bitwise.rb +0 -13
  31. data/lib/rqrcode/qrcode/qr_8bit_byte.rb +0 -36
  32. data/lib/rqrcode/qrcode/qr_alphanumeric.rb +0 -47
  33. data/lib/rqrcode/qrcode/qr_bit_buffer.rb +0 -99
  34. data/lib/rqrcode/qrcode/qr_code.rb +0 -585
  35. data/lib/rqrcode/qrcode/qr_math.rb +0 -63
  36. data/lib/rqrcode/qrcode/qr_numeric.rb +0 -57
  37. data/lib/rqrcode/qrcode/qr_polynomial.rb +0 -78
  38. data/lib/rqrcode/qrcode/qr_rs_block.rb +0 -314
  39. data/lib/rqrcode/qrcode/qr_util.rb +0 -272
  40. data/test/data.rb +0 -25
  41. data/test/test_helper.rb +0 -5
  42. data/test/test_regresions.rb +0 -10
  43. data/test/test_rqrcode.rb +0 -155
  44. data/test/test_rqrcode_export.rb +0 -27
@@ -1,19 +1,8 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Copyright 2008 by Duncan Robertson (duncan@whomwah.com).
5
- # All rights reserved.
6
-
7
- # Permission is granted for use, copying, modification, distribution,
8
- # and distribution of modified versions of this work as long as the
9
- # above copyright notice is included.
10
- #++
11
-
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
-
14
- require "rqrcode/core_ext"
15
- require "rqrcode/qrcode"
16
- require 'rqrcode/export/png'
17
- require 'rqrcode/export/svg'
18
- require 'rqrcode/export/html'
19
- require 'rqrcode/export/ansi'
1
+ # frozen_string_literal: true
2
+
3
+ module RQRCode
4
+ require 'rqrcode_core'
5
+ require 'rqrcode/qrcode'
6
+ require 'rqrcode/export'
7
+ require 'rqrcode/version'
8
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rqrcode/export/ansi'
4
+ require 'rqrcode/export/html'
5
+ require 'rqrcode/export/png'
6
+ require 'rqrcode/export/svg'
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RQRCode
2
4
  module Export
3
5
  module ANSI
4
- ##
6
+ #
5
7
  # Returns a string of the QR code as
6
8
  # characters writen with ANSI background set.
7
- #
8
- # Options:
9
+ #
10
+ # Options:
9
11
  # light: Foreground ("\033[47m")
10
12
  # dark: Background ANSI code. ("\033[47m")
11
13
  # fill_character: The written character. (' ')
@@ -19,23 +21,20 @@ module RQRCode
19
21
  quiet_zone_size: 4
20
22
  }.merge(options)
21
23
 
22
- normal = "\033[m"
24
+ normal = "\033[m\n"
23
25
  light = options.fetch(:light)
24
26
  dark = options.fetch(:dark)
25
27
  fill_character = options.fetch(:fill_character)
26
28
  quiet_zone_size = options.fetch(:quiet_zone_size)
29
+ output = []
27
30
 
28
- output = ''
29
-
30
- @modules.each_index do |c|
31
-
31
+ @qrcode.modules.each_index do |c|
32
32
  # start row with quiet zone
33
33
  row = light + fill_character * quiet_zone_size
34
34
  previous_dark = false
35
35
 
36
- @modules.each_index do |r|
37
- if is_dark(c, r)
38
- # dark
36
+ @qrcode.modules.each_index do |r|
37
+ if @qrcode.checked?(c, r)
39
38
  if previous_dark != true
40
39
  row << dark
41
40
  previous_dark = true
@@ -58,18 +57,18 @@ module RQRCode
58
57
  row << fill_character * quiet_zone_size
59
58
 
60
59
  # always end with reset and newline
61
- row << normal + "\n"
60
+ row << normal
62
61
 
63
62
  output << row
64
63
  end
65
64
 
66
65
  # count the row width so we can add quiet zone rows
67
- width = output.each_line.first.scan(fill_character).length
66
+ width = output.first.scan(fill_character).length
68
67
 
69
- quiet_row = light + fill_character * width + normal + "\n"
68
+ quiet_row = light + fill_character * width + normal
70
69
  quiet_rows = quiet_row * quiet_zone_size
71
70
 
72
- return quiet_rows + output + quiet_rows
71
+ return quiet_rows + output.join + quiet_rows
73
72
  end
74
73
  end
75
74
  end
@@ -1,8 +1,10 @@
1
- # Use this module to HTML-ify the QR code if you just want the default HTML
1
+ # frozen_string_literal: true
2
+
2
3
  module RQRCode
3
4
  module Export
4
5
  module HTML
5
-
6
+ #
7
+ # Use this module to HTML-ify the QR code if you just want the default HTML
6
8
  def as_html
7
9
  ['<table>', rows.as_html, '</table>'].join
8
10
  end
@@ -10,7 +12,7 @@ module RQRCode
10
12
  private
11
13
 
12
14
  def rows
13
- Rows.new(self)
15
+ Rows.new(@qrcode)
14
16
  end
15
17
 
16
18
  class Rows < Struct.new(:qr)
@@ -39,11 +41,7 @@ module RQRCode
39
41
  end
40
42
 
41
43
  def html_class
42
- dark? ? 'black' : 'white'
43
- end
44
-
45
- def dark?
46
- qr.dark?(row_index, col_index)
44
+ qr.checked?(row_index, col_index) ? 'black' : 'white'
47
45
  end
48
46
  end
49
47
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'chunky_png'
2
3
 
3
4
  # This class creates PNG files.
@@ -5,21 +6,21 @@ require 'chunky_png'
5
6
  module RQRCode
6
7
  module Export
7
8
  module PNG
8
-
9
+ #
9
10
  # Render the PNG from the Qrcode.
10
11
  #
11
12
  # There are two sizing algoritams.
12
13
  #
13
14
  # - Original that can result in blurry and hard to scan images
14
15
  # - Google's Chart API inspired sizing that resizes the module size to fit within the given image size.
15
- #
16
+ #
16
17
  # The Googleis one will be used when no options are given or when the new size option is used.
17
18
  #
18
- # Options:
19
+ # Options:
19
20
  # fill - Background ChunkyPNG::Color, defaults to 'white'
20
21
  # color - Foreground ChunkyPNG::Color, defaults to 'black'
21
22
  #
22
- # *Googleis*
23
+ # *Googleis*
23
24
  # size - Total size of PNG in pixels. The module size is calculated so it fits. (defaults to 90)
24
25
  # border_modules - Width of white border around in modules. (defaults to 4).
25
26
  #
@@ -33,7 +34,6 @@ module RQRCode
33
34
  # Defaults to 90x90 pixels, customizable by option.
34
35
  #
35
36
  def as_png(options = {})
36
-
37
37
  default_img_options = {
38
38
  :resize_gte_to => false,
39
39
  :resize_exactly_to => false,
@@ -44,26 +44,26 @@ module RQRCode
44
44
  :file => false,
45
45
  :module_px_size => 6
46
46
  }
47
-
47
+
48
48
  googleis = options.length == 0 || (options[:size] != nil)
49
-
49
+
50
50
  options = default_img_options.merge(options) # reverse_merge
51
51
 
52
52
  fill = ChunkyPNG::Color(options[:fill])
53
53
  color = ChunkyPNG::Color(options[:color])
54
54
  output_file = options[:file]
55
-
55
+
56
56
  module_px_size = nil
57
57
  border_px = nil
58
58
  png = nil
59
-
59
+
60
60
  if googleis
61
61
  total_image_size = options[:size]
62
62
  border_modules = options[:border_modules]
63
63
 
64
- module_px_size = (total_image_size.to_f / (self.module_count + 2 * border_modules).to_f).floor.to_i
64
+ module_px_size = (total_image_size.to_f / (@qrcode.module_count + 2 * border_modules).to_f).floor.to_i
65
65
 
66
- img_size = module_px_size * self.module_count
66
+ img_size = module_px_size * @qrcode.module_count
67
67
 
68
68
  remaining = total_image_size - img_size
69
69
  border_px = (remaining / 2.0).floor.to_i
@@ -73,7 +73,7 @@ module RQRCode
73
73
  border = options[:border_modules]
74
74
  total_border = border * 2
75
75
  module_px_size = if options[:resize_gte_to]
76
- (options[:resize_gte_to].to_f / (self.module_count + total_border).to_f).ceil.to_i
76
+ (options[:resize_gte_to].to_f / (@qrcode.module_count + total_border).to_f).ceil.to_i
77
77
  else
78
78
  options[:module_px_size]
79
79
  end
@@ -81,15 +81,15 @@ module RQRCode
81
81
  total_border_px = border_px * 2
82
82
  resize_to = options[:resize_exactly_to]
83
83
 
84
- img_size = module_px_size * self.module_count
84
+ img_size = module_px_size * @qrcode.module_count
85
85
  total_img_size = img_size + total_border_px
86
86
 
87
87
  png = ChunkyPNG::Image.new(total_img_size, total_img_size, fill)
88
88
  end
89
89
 
90
- self.modules.each_index do |x|
91
- self.modules.each_index do |y|
92
- if self.dark?(x, y)
90
+ @qrcode.modules.each_index do |x|
91
+ @qrcode.modules.each_index do |y|
92
+ if @qrcode.checked?(x, y)
93
93
  (0...module_px_size).each do |i|
94
94
  (0...module_px_size).each do |j|
95
95
  png[(y * module_px_size) + border_px + j , (x * module_px_size) + border_px + i] = color
@@ -98,9 +98,9 @@ module RQRCode
98
98
  end
99
99
  end
100
100
  end
101
-
101
+
102
102
  if !googleis && resize_to
103
- png = png.resize(resize_to, resize_to)
103
+ png = png.resize(resize_to, resize_to)
104
104
  end
105
105
 
106
106
 
@@ -109,7 +109,6 @@ module RQRCode
109
109
  end
110
110
  png
111
111
  end
112
-
113
112
  end
114
113
  end
115
114
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class creates a SVG files.
2
4
  # Code from: https://github.com/samvincent/rqrcode-rails3
3
5
  module RQRCode
4
6
  module Export
5
-
6
7
  module SVG
7
-
8
+ #
8
9
  # Render the SVG from the Qrcode.
9
10
  #
10
11
  # Options:
@@ -21,20 +22,20 @@ module RQRCode
21
22
  module_size = options[:module_size] || 11
22
23
 
23
24
  # height and width dependent on offset and QR complexity
24
- dimension = (self.module_count*module_size) + (2*offset)
25
+ dimension = (@qrcode.module_count*module_size) + (2*offset)
25
26
 
26
27
  xml_tag = %{<?xml version="1.0" standalone="yes"?>}
27
28
  open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}" shape-rendering="#{shape_rendering}">}
28
29
  close_tag = "</svg>"
29
30
 
30
31
  result = []
31
- self.modules.each_index do |c|
32
+ @qrcode.modules.each_index do |c|
32
33
  tmp = []
33
- self.modules.each_index do |r|
34
+ @qrcode.modules.each_index do |r|
34
35
  y = c*module_size + offset
35
36
  x = r*module_size + offset
36
37
 
37
- next unless self.is_dark(c, r)
38
+ next unless @qrcode.checked?(c, r)
38
39
  tmp << %{<rect width="#{module_size}" height="#{module_size}" x="#{x}" y="#{y}" style="fill:##{color}"/>}
39
40
  end
40
41
  result << tmp.join
@@ -1,4 +1,3 @@
1
- Dir[File.dirname(__FILE__) + "/qrcode/*.rb"].sort.each do |path|
2
- filename = File.basename(path)
3
- require "rqrcode/qrcode/#{filename}"
4
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rqrcode/qrcode/qrcode'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module RQRCode #:nodoc:
6
+ class QRCode
7
+ extend Forwardable
8
+ def_delegators :@qrcode, :to_s
9
+ def_delegators :@qrcode, :modules # deprecated
10
+
11
+ attr_reader :qrcode
12
+
13
+ def initialize(string, *args)
14
+ @qrcode = RQRCodeCore::QRCode.new(string, args)
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RQRCode
2
- VERSION = "0.10.1"
4
+ VERSION = "1.0.0.pre"
3
5
  end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "rqrcode/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "rqrcode"
9
+ spec.version = RQRCode::VERSION
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.authors = ["Duncan Robertson"]
12
+ spec.email = ["duncan@whomwah.com"]
13
+
14
+ spec.summary = %q{A library to encode QR Codes}
15
+ spec.description = <<EOF
16
+ rqrcode is a library for encoding QR Codes. The simple
17
+ interface allows you to create QR Code data structures
18
+ and then render them in the way you choose.
19
+ EOF
20
+ spec.homepage = "https://github.com/whomwah/rqrcode"
21
+ spec.license = "MIT"
22
+
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.required_ruby_version = '~> 2.3'
31
+ spec.add_dependency 'rqrcode_core', '~> 0.1.0'
32
+ spec.add_dependency 'chunky_png', "~> 1.0"
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 12.0"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ end
metadata CHANGED
@@ -1,102 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
- - Björn Blomqvist
8
7
  - Duncan Robertson
9
8
  autorequire:
10
- bindir: bin
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rqrcode_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: chunky_png
16
29
  requirement: !ruby/object:Gem::Requirement
17
30
  requirements:
18
- - - ~>
31
+ - - "~>"
19
32
  - !ruby/object:Gem::Version
20
33
  version: '1.0'
21
34
  type: :runtime
22
35
  prerelease: false
23
36
  version_requirements: !ruby/object:Gem::Requirement
24
37
  requirements:
25
- - - ~>
38
+ - - "~>"
26
39
  - !ruby/object:Gem::Version
27
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
28
55
  - !ruby/object:Gem::Dependency
29
56
  name: rake
30
57
  requirement: !ruby/object:Gem::Requirement
31
58
  requirements:
32
- - - '>='
59
+ - - "~>"
33
60
  - !ruby/object:Gem::Version
34
- version: '0'
61
+ version: '12.0'
35
62
  type: :development
36
63
  prerelease: false
37
64
  version_requirements: !ruby/object:Gem::Requirement
38
65
  requirements:
39
- - - '>='
66
+ - - "~>"
40
67
  - !ruby/object:Gem::Version
41
- version: '0'
68
+ version: '12.0'
42
69
  - !ruby/object:Gem::Dependency
43
- name: bundler
70
+ name: minitest
44
71
  requirement: !ruby/object:Gem::Requirement
45
72
  requirements:
46
- - - '>='
73
+ - - "~>"
47
74
  - !ruby/object:Gem::Version
48
- version: 1.0.0
75
+ version: '5.0'
49
76
  type: :development
50
77
  prerelease: false
51
78
  version_requirements: !ruby/object:Gem::Requirement
52
79
  requirements:
53
- - - '>='
80
+ - - "~>"
54
81
  - !ruby/object:Gem::Version
55
- version: 1.0.0
82
+ version: '5.0'
56
83
  description: |
57
- rQRCode is a library for encoding QR Codes. The simple
84
+ rqrcode is a library for encoding QR Codes. The simple
58
85
  interface allows you to create QR Code data structures
59
- ready to be displayed in the way you choose.
86
+ and then render them in the way you choose.
60
87
  email:
61
- - darwin@bits2life.com
88
+ - duncan@whomwah.com
62
89
  executables: []
63
90
  extensions: []
64
- extra_rdoc_files:
65
- - README.md
66
- - CHANGELOG
67
- - LICENSE
91
+ extra_rdoc_files: []
68
92
  files:
69
- - CHANGELOG
70
- - LICENSE
93
+ - ".gitignore"
94
+ - Gemfile
95
+ - LICENSE.txt
71
96
  - README.md
97
+ - Rakefile
98
+ - _config.yml
99
+ - bin/console
100
+ - bin/setup
101
+ - images/ansi-screen-shot.png
102
+ - images/github-qrcode.png
103
+ - images/github-qrcode.svg
72
104
  - lib/rqrcode.rb
73
- - lib/rqrcode/core_ext.rb
74
- - lib/rqrcode/core_ext/array.rb
75
- - lib/rqrcode/core_ext/array/behavior.rb
76
- - lib/rqrcode/core_ext/integer.rb
77
- - lib/rqrcode/core_ext/integer/bitwise.rb
105
+ - lib/rqrcode/export.rb
78
106
  - lib/rqrcode/export/ansi.rb
79
107
  - lib/rqrcode/export/html.rb
80
108
  - lib/rqrcode/export/png.rb
81
109
  - lib/rqrcode/export/svg.rb
82
110
  - lib/rqrcode/qrcode.rb
83
- - lib/rqrcode/qrcode/qr_8bit_byte.rb
84
- - lib/rqrcode/qrcode/qr_alphanumeric.rb
85
- - lib/rqrcode/qrcode/qr_bit_buffer.rb
86
- - lib/rqrcode/qrcode/qr_code.rb
87
- - lib/rqrcode/qrcode/qr_math.rb
88
- - lib/rqrcode/qrcode/qr_numeric.rb
89
- - lib/rqrcode/qrcode/qr_polynomial.rb
90
- - lib/rqrcode/qrcode/qr_rs_block.rb
91
- - lib/rqrcode/qrcode/qr_util.rb
111
+ - lib/rqrcode/qrcode/qrcode.rb
92
112
  - lib/rqrcode/version.rb
93
- - test/data.rb
94
- - test/test_helper.rb
95
- - test/test_regresions.rb
96
- - test/test_rqrcode.rb
97
- - test/test_rqrcode_export.rb
113
+ - rqrcode.gemspec
98
114
  homepage: https://github.com/whomwah/rqrcode
99
- licenses: []
115
+ licenses:
116
+ - MIT
100
117
  metadata: {}
101
118
  post_install_message:
102
119
  rdoc_options: []
@@ -104,23 +121,17 @@ require_paths:
104
121
  - lib
105
122
  required_ruby_version: !ruby/object:Gem::Requirement
106
123
  requirements:
107
- - - '>='
124
+ - - "~>"
108
125
  - !ruby/object:Gem::Version
109
- version: '0'
126
+ version: '2.3'
110
127
  required_rubygems_version: !ruby/object:Gem::Requirement
111
128
  requirements:
112
- - - '>='
129
+ - - ">"
113
130
  - !ruby/object:Gem::Version
114
- version: 1.3.6
131
+ version: 1.3.1
115
132
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.4.8
133
+ rubygems_version: 3.0.3
118
134
  signing_key:
119
135
  specification_version: 4
120
136
  summary: A library to encode QR Codes
121
- test_files:
122
- - test/data.rb
123
- - test/test_helper.rb
124
- - test/test_regresions.rb
125
- - test/test_rqrcode.rb
126
- - test/test_rqrcode_export.rb
137
+ test_files: []