rqrcode_png_bin 0.2.0 → 0.2.2

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: 1d8b25f22649cad03bed2e0f29707bf991912827
4
- data.tar.gz: a5025faa9e43d92d5d6ccaa20271df1cda94b735
3
+ metadata.gz: bb970ba18e7c0c2d194a661f91c5b18be86f9b9f
4
+ data.tar.gz: aec91a7e72a9e9b0c9d35ff1f38e72ee4b9afd95
5
5
  SHA512:
6
- metadata.gz: 89311896686672e9570234011c54ed1a1da183207939cdd7b2d45c8b10f6aadfc1829c4225c42275b2c4c9776178ed46dcd66913a6cddf3173d1a8f9aa1a3f2c
7
- data.tar.gz: 30fa3402075dad4fe69ddd2b3390a50b3db4df885bcaa499e64a76b9b870dbc200aeaa8b7b5be047cb98ef4ad238001dd015000f45df612c255aac6256fceed6
6
+ metadata.gz: e1ce4c77f9c5f6f3f40c1be2848546e41af9319cd2152bf855927557d78ab15815ce77e277fd4dd0e0aefcae0a453ecac8ea3fd90f1a624159cfad15df645cd3
7
+ data.tar.gz: 78dd22051997a54305d70dc1e5b65c1ae7c9ec1984b6ccc862b405fd0b5bdf83ad237f63b9bacf18334d6e8cfa6077c8e611071ce5965ffd2c4219f6e256eebf
@@ -5,15 +5,18 @@ module RqrcodePngBin
5
5
  def initialize(argv = [])
6
6
  @argv = argv
7
7
 
8
+ @border_modules = 4
8
9
  @canvas = nil
9
10
  @file = nil
10
11
  @level = :m
12
+ @mode = nil
13
+ @px_per_module = nil
11
14
  @size = 4
12
15
  @stdin = nil
13
16
 
14
17
  parser.parse!(@argv)
15
18
  end
16
- attr_reader :canvas, :file, :level, :size, :stdin
19
+ attr_reader :border_modules, :canvas, :file, :level, :mode, :px_per_module, :size, :stdin
17
20
 
18
21
  def run
19
22
  if file
@@ -30,10 +33,7 @@ module RqrcodePngBin
30
33
  end
31
34
 
32
35
  def generate_png(str)
33
- options = {}
34
- options[:size] = canvas.first if canvas
35
-
36
- RQRCode::QRCode.new(encoded_str(str), opts).as_png(options)
36
+ RQRCode::QRCode.new(encoded_str(str), opts).as_png(png_opts)
37
37
  end
38
38
 
39
39
  def encoded_str(str)
@@ -60,6 +60,20 @@ module RqrcodePngBin
60
60
  :size => @size,
61
61
  :level => @level
62
62
  }
63
+
64
+ h[:mode] = @mode if @mode
65
+
66
+ h
67
+ end
68
+
69
+ def png_opts
70
+ h = {}
71
+
72
+ h[:size] = canvas if canvas
73
+ h[:border_modules] = border_modules
74
+ h[:module_px_size] = px_per_module if px_per_module
75
+
76
+ h
63
77
  end
64
78
 
65
79
  #
@@ -70,13 +84,18 @@ module RqrcodePngBin
70
84
  opt.version = VERSION
71
85
  opt.banner = "Usage: rqrcode_png [option] string"
72
86
 
73
- opt.on('-c', '--canvas CANVAS (ex 200x200)') {|v|
74
- re = %r{\A([0-9]+)x([0-9]+)\z}
75
-
76
- if v =~ re
77
- @canvas = [$1.to_i, $2.to_i]
87
+ opt.on('-b', '--border-modules BORDER') {|v|
88
+ if v =~ /\A[0-9]+\z/
89
+ @border_modules = v.to_i
90
+ else
91
+ raise ArgumentError, "option border modules should be integer"
92
+ end
93
+ }
94
+ opt.on('-c', '--canvas CANVAS (ex 200)') {|v|
95
+ if v =~ /\A[0-9]+\z/
96
+ @canvas = v.to_i
78
97
  else
79
- raise ArgumentError, "option canvas should match #{re}"
98
+ raise ArgumentError, "option canvas should match be integer"
80
99
  end
81
100
  }
82
101
  opt.on('-f', '--from-file FILE') {|v|
@@ -86,7 +105,7 @@ module RqrcodePngBin
86
105
  raise ArgumentError, "file you specified '#{v}' does not exist"
87
106
  end
88
107
  }
89
- opt.on('-l', '--level LEVEL (default m)') {|v|
108
+ opt.on('-l', '--level l|m|q|h (default m)') {|v|
90
109
  options = %w(l m q h)
91
110
 
92
111
  if options.include?(v)
@@ -95,6 +114,22 @@ module RqrcodePngBin
95
114
  raise ArgumentError, "option level should be included #{options}"
96
115
  end
97
116
  }
117
+ opt.on('-m', '--mode MODE') {|v|
118
+ options = %w(number alphanumeric byte_8bit)
119
+
120
+ if options.include?(v)
121
+ @mode = v.to_sym
122
+ else
123
+ raise ArgumentError, "option mode should be included #{options}"
124
+ end
125
+ }
126
+ opt.on('-p', '--pixels-per-module PIXELS') {|v|
127
+ if v =~ /\A[0-9]+\z/
128
+ @px_per_module = v.to_i
129
+ else
130
+ raise ArgumentError, "option pixels per module should be integer"
131
+ end
132
+ }
98
133
  opt.on('-s', '--size SIZE (default 4)') {|v|
99
134
  re = %r{\A[0-9]+\z}
100
135
 
@@ -1,3 +1,3 @@
1
1
  module RqrcodePngBin
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/spec/app_spec.rb CHANGED
@@ -7,6 +7,23 @@ describe RqrcodePngBin::App do
7
7
  end
8
8
 
9
9
  describe '#parser' do
10
+ context 'border modules' do
11
+ context 'nil' do
12
+ it {
13
+ expect(app.border_modules).to be(4)
14
+ }
15
+ end
16
+ context '4' do
17
+ it {
18
+ expect(app(%w(-b 4)).border_modules).to be(4)
19
+ }
20
+ end
21
+ context 'a' do
22
+ it {
23
+ expect {app(%w(-b a)).border_modules}.to raise_error(ArgumentError)
24
+ }
25
+ end
26
+ end
10
27
  context 'canvas' do
11
28
  context 'nil' do
12
29
  it {
@@ -15,7 +32,7 @@ describe RqrcodePngBin::App do
15
32
  end
16
33
  context '200x200' do
17
34
  it {
18
- expect(app(%w(-c 200x200)).canvas).to be == [200, 200]
35
+ expect(app(%w(-c 200)).canvas).to be(200)
19
36
  }
20
37
  end
21
38
  context 'abc' do
@@ -58,6 +75,40 @@ describe RqrcodePngBin::App do
58
75
  }
59
76
  end
60
77
  end
78
+ context 'mode' do
79
+ context 'nil' do
80
+ it {
81
+ expect(app.mode).to be_nil
82
+ }
83
+ end
84
+ context 'number' do
85
+ it {
86
+ expect(app(%w(-m number)).mode).to be(:number)
87
+ }
88
+ end
89
+ context 'foo' do
90
+ it {
91
+ expect {app(%w(-m foo))}.to raise_error(ArgumentError)
92
+ }
93
+ end
94
+ end
95
+ context 'px_per_module' do
96
+ context 'nil' do
97
+ it {
98
+ expect(app.px_per_module).to be_nil
99
+ }
100
+ end
101
+ context '10' do
102
+ it {
103
+ expect(app(%w(-p 10)).px_per_module).to be(10)
104
+ }
105
+ end
106
+ context 'a' do
107
+ it {
108
+ expect {app(%w(-p a))}.to raise_error(ArgumentError)
109
+ }
110
+ end
111
+ end
61
112
  context 'size' do
62
113
  context 'nil' do
63
114
  it {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode_png_bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - wtnabe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rqrcode