rqrcode 0.7.0 → 0.8.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
2
  SHA1:
3
- metadata.gz: 1275547d28967654aa0f1ba1a450c5daa31c582a
4
- data.tar.gz: c6ae31e4cdea2370f20a147cbc6f41f6d7d2fdc6
3
+ metadata.gz: 46c6e005cfad5a06130d1057cb3339a9536876d7
4
+ data.tar.gz: 43052e7598d0ca24b55ccdac80c112d110d6023f
5
5
  SHA512:
6
- metadata.gz: 916f34ba9af9afffbfd8ba55116fc130b32a3ffb89db779da2af89df0c167fe49138fd625a33f1f48d648729ae488742921b2dfa10f6349743ff9ac7d865f7e3
7
- data.tar.gz: 6ebffce16883fcf0951c6bd601915e1335a709b216cfa2255e1c56b45e496e42b301724f117d81134f403a93960d743b7eb3676239584562622eec216a33226e
6
+ metadata.gz: 4da648696490c9dea757030a8f1a33ec731532704bca8707dac941729791bb1f4c7d68a39dc83bbeab0df39becc719b3b70b383c1ae88a4600ec7a6742f36a10
7
+ data.tar.gz: ed6067dc3533be6f1ebdbd3eea7e34a4caca62d868a469ad09f7dbb963a72c13c1dc75ab3f29385f27317e9601a7e0e156d91cc95c9c757fe9719f7a595003fc
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  /pkg/
2
2
  .rvmrc
3
- Gemfile.lock
3
+ Gemfile.lock
4
+ *.sublime-project
5
+ *.sublime-workspace
@@ -1,9 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.2.3
4
4
  - 2.1.6
5
5
  - 2.0.0
6
6
  - 1.9.3
7
- - 1.8.7
8
- - jruby-18mode
9
7
  - jruby-19mode
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.8.0* (Dec 18, 2015)
2
+
3
+ - Added numeric QR code support
4
+ - Dropped Ruby v1.8 support
5
+
1
6
  *0.7.0* (Aug 15, 2015)
2
7
 
3
8
  - Added shape_rendering option for as_svg
data/README.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  ## Short changelog
6
6
 
7
+ *0.8.0* (Dec 18, 2015)
8
+
9
+ - Added numeric QR code support
10
+ - Dropped Ruby v1.8 support
11
+
7
12
  *0.7.0* (Aug 15, 2015)
8
13
 
9
14
  - Added shape_rendering option for as_svg
@@ -76,9 +81,8 @@ png = qrcode.as_png(
76
81
  color: 'black',
77
82
  size: 120,
78
83
  border_modules: 4,
79
- file: false,
80
84
  module_px_size: 6,
81
- output_file: nil # path to write
85
+ file: nil # path to write
82
86
  )
83
87
  ```
84
88
 
@@ -141,6 +145,17 @@ qr.modules.each do |row|
141
145
  end
142
146
  ```
143
147
 
148
+ ## Specifying QR code mode
149
+
150
+ Sometimes you may want to specify the QR code mode explicitly.
151
+
152
+ It is done via the `mode` option. Allowed values are: `number`, `alphanumeric` and `byte_8bit`.
153
+
154
+ ```ruby
155
+ qr = RQRCode::QRCode.new( '1234567890', :size => 2, :level => :m, :mode => :number )
156
+ ```
157
+
158
+
144
159
  ## API Documentation
145
160
 
146
161
  [http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
data/TODO.md CHANGED
@@ -1,5 +1,4 @@
1
1
  - Add to_ansi rendering_
2
- - Add Numeric mode
3
2
  - Add Kanji mode
4
3
  - Add ECI Mode
5
4
  - Improved performance for large QR codes
@@ -68,6 +68,13 @@ module RQRCode
68
68
  put(length, QRUtil.get_length_in_bits(QRMODE[:mode_alpha_numk], @version))
69
69
 
70
70
  end
71
+
72
+ def numeric_encoding_start(length)
73
+
74
+ put( QRMODE[:mode_number], 4 )
75
+ put(length, QRUtil.get_length_in_bits(QRMODE[:mode_number], @version))
76
+
77
+ end
71
78
 
72
79
  def pad_until(prefered_size)
73
80
  # Align on byte
@@ -18,6 +18,12 @@ module RQRCode #:nodoc:
18
18
  :mode_kanji => 1 << 3
19
19
  }
20
20
 
21
+ QRMODE_NAME = {
22
+ :number => :mode_number,
23
+ :alphanumeric => :mode_alpha_numk,
24
+ :byte_8bit => :mode_8bit_byte
25
+ }
26
+
21
27
  QRERRORCORRECTLEVEL = {
22
28
  :l => 1,
23
29
  :m => 0,
@@ -84,7 +90,7 @@ module RQRCode #:nodoc:
84
90
  # and an optional hash of any other. Here's a few examples:
85
91
  #
86
92
  # qr = RQRCode::QRCode.new('hello world')
87
- # qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
93
+ # qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m, :mode => :alphanumeric )
88
94
  #
89
95
 
90
96
  class QRCode
@@ -99,8 +105,13 @@ module RQRCode #:nodoc:
99
105
  # * Level :m 15% of code can be restored
100
106
  # * Level :q 25% of code can be restored
101
107
  # * Level :h 30% of code can be restored (default :h)
108
+ # # mode - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data):
109
+ # * :number
110
+ # * :alphanumeric
111
+ # * :byte_8bit
112
+ # * :kanji
102
113
  #
103
- # qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
114
+ # qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m, :mode => :alphanumeric )
104
115
  #
105
116
 
106
117
  def initialize( string, *args )
@@ -117,7 +128,8 @@ module RQRCode #:nodoc:
117
128
 
118
129
  @data = string
119
130
 
120
- mode = QRAlphanumeric.valid_data?( @data ) ? :mode_alpha_numk : :mode_8bit_byte
131
+ mode = QRMODE_NAME[(options[:mode] || '').to_sym]
132
+ mode ||= QRAlphanumeric.valid_data?( @data ) ? :mode_alpha_numk : :mode_8bit_byte # deprecate?
121
133
 
122
134
  max_size_array = QRMAXDIGITS[level][mode]
123
135
  size = options[:size] || smallest_size_for(string, max_size_array)
@@ -130,7 +142,16 @@ module RQRCode #:nodoc:
130
142
  @version = size
131
143
  @module_count = @version * 4 + QRPOSITIONPATTERNLENGTH
132
144
  @modules = Array.new( @module_count )
133
- @data_list = (mode == :mode_alpha_numk) ? QRAlphanumeric.new( @data ) : QR8bitByte.new( @data )
145
+ @data_list =
146
+ case mode
147
+ when :mode_number
148
+ QRNumeric.new( @data )
149
+ when :mode_alpha_numk
150
+ QRAlphanumeric.new( @data )
151
+ else
152
+ QR8bitByte.new( @data )
153
+ end
154
+
134
155
  @data_cache = nil
135
156
  self.make
136
157
  end
@@ -0,0 +1,66 @@
1
+ module RQRCode
2
+
3
+ NUMERIC = ['0','1','2','3','4','5','6','7','8','9'].freeze
4
+
5
+ class QRNumeric
6
+ attr_reader :mode
7
+
8
+ def initialize( data )
9
+ @mode = QRMODE[:mode_number]
10
+
11
+ raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)
12
+
13
+ @data = data;
14
+ end
15
+
16
+
17
+ def get_length
18
+ @data.size
19
+ end
20
+
21
+ def self.valid_data? data
22
+ data.each_char do |s|
23
+ return false if NUMERIC.index(s).nil?
24
+ end
25
+ true
26
+ end
27
+
28
+
29
+ def write( buffer)
30
+ buffer.numeric_encoding_start(get_length)
31
+
32
+ (@data.size).times do |i|
33
+ if i % 3 == 0
34
+ chars = @data[i]
35
+
36
+ if @data[i + 1].present?
37
+ chars << @data[i + 1]
38
+ end
39
+
40
+ if @data[i + 2].present?
41
+ chars << @data[i + 2]
42
+ end
43
+
44
+ bit_length = get_bit_length(chars.length)
45
+ buffer.put( get_code(chars), bit_length )
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ NUMBER_LENGTH = {
53
+ 3 => 10,
54
+ 2 => 7,
55
+ 1 => 4
56
+ }.freeze
57
+
58
+ def get_bit_length(length)
59
+ NUMBER_LENGTH[length]
60
+ end
61
+
62
+ def get_code(chars)
63
+ chars.to_i
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module RQRCode
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -18,7 +18,7 @@ EOF
18
18
 
19
19
  s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
20
20
 
21
- s.add_dependency 'chunky_png'
21
+ s.add_dependency 'chunky_png', "~> 1.0"
22
22
 
23
23
  s.add_development_dependency "rake"
24
24
  s.add_development_dependency("bundler", ">= 1.0.0")
@@ -96,6 +96,13 @@ class QRCodeTest < Test::Unit::TestCase
96
96
  assert_equal "xxxxxxx xxx xxxxxxx\n", qr.to_s[0..21]
97
97
  end
98
98
 
99
+ def test_numeric_2_M
100
+ data = '279042272585972554922067893753871413584876543211601021503002'
101
+
102
+ qr = RQRCode::QRCode.new(data, size: 2, level: :m, mode: :number)
103
+ assert_equal "xxxxxxx x x x xxxxxxx\n", qr.to_s[0..25]
104
+ end
105
+
99
106
  def test_rszf_error_not_thrown
100
107
  assert RQRCode::QRCode.new('2 1058 657682')
101
108
  assert RQRCode::QRCode.new("40952", :size => 1, :level => :h)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Blomqvist
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-15 00:00:00.000000000 Z
12
+ date: 2015-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +89,7 @@ files:
89
89
  - lib/rqrcode/qrcode/qr_bit_buffer.rb
90
90
  - lib/rqrcode/qrcode/qr_code.rb
91
91
  - lib/rqrcode/qrcode/qr_math.rb
92
+ - lib/rqrcode/qrcode/qr_numeric.rb
92
93
  - lib/rqrcode/qrcode/qr_polynomial.rb
93
94
  - lib/rqrcode/qrcode/qr_rs_block.rb
94
95
  - lib/rqrcode/qrcode/qr_util.rb