rqrcode_png_bin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/rqrcode_png_bin/app.rb +37 -17
- data/lib/rqrcode_png_bin/file_reader.rb +33 -0
- data/lib/rqrcode_png_bin/version.rb +1 -1
- data/lib/rqrcode_png_bin.rb +1 -0
- data/spec/{rqrcode_png_bin_spec.rb → app_spec.rb} +30 -13
- data/spec/file_reader_spec.rb +49 -0
- data/spec/support/dummy +0 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3af632bfe45808e81abd4c88cfb19cd0cc842e87
|
4
|
+
data.tar.gz: 49e8deddb8c9236ab199df2fb99de0d51b852b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25fb3ed536294faaab8a92c736cc0bfad2843721ffb35643862ebed21857b9aceafeefa349e52ef672d7c273320a2b2c84238c4730bb78725724692848a45f92
|
7
|
+
data.tar.gz: df4057489ee9c0673b231bec9935b72ed3b0daf2c551f1c20c36fcdb69972263aced58090ef3b88f5eec28ec81c008d65e42326088d126e076fc0e099cae7283
|
data/README.md
CHANGED
@@ -8,7 +8,20 @@ command line interface for rqrcode_png
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
rqrcode_png STRING > qrcode.png
|
11
|
+
$ rqrcode_png STRING > qrcode.png
|
12
|
+
|
13
|
+
or
|
14
|
+
|
15
|
+
$ rqrcode_png -f TSV_FILE
|
16
|
+
|
17
|
+
## TSV format
|
18
|
+
|
19
|
+
Two formats exists.
|
20
|
+
|
21
|
+
1. 1 line : 1 text for encoding
|
22
|
+
2. 1 line : 1 text for encoding\<TAB\>1 filename
|
23
|
+
|
24
|
+
If you choose format one, output filename is deterimined automatically from text for encoding (with CGI#escape).
|
12
25
|
|
13
26
|
## Contributing
|
14
27
|
|
data/lib/rqrcode_png_bin/app.rb
CHANGED
@@ -5,25 +5,37 @@ module RqrcodePngBin
|
|
5
5
|
class App
|
6
6
|
def initialize(argv = [])
|
7
7
|
@argv = argv
|
8
|
-
|
9
|
-
@level = :m
|
8
|
+
|
10
9
|
@canvas = nil
|
10
|
+
@file = nil
|
11
|
+
@level = :m
|
12
|
+
@size = 4
|
11
13
|
|
12
14
|
parser.parse!(@argv)
|
13
15
|
end
|
14
|
-
attr_reader :
|
16
|
+
attr_reader :canvas, :file, :level, :size
|
15
17
|
|
16
18
|
def run
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
if file
|
20
|
+
FileReader.new(file).each {|str, dest|
|
21
|
+
open(dest, 'wb') {|f|
|
22
|
+
f.puts generate_png(str)
|
23
|
+
}
|
24
|
+
}
|
25
|
+
elsif str
|
26
|
+
STDOUT.puts generate_png(str)
|
22
27
|
else
|
23
|
-
STDERR.puts "rqrcode_png #{VERSION}",
|
28
|
+
STDERR.puts "rqrcode_png #{VERSION}", '', parser.help
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
32
|
+
def generate_png(str)
|
33
|
+
png = RQRCode::QRCode.new(str, opts).to_img
|
34
|
+
png = png.resize(*canvas) if canvas
|
35
|
+
|
36
|
+
png
|
37
|
+
end
|
38
|
+
|
27
39
|
#
|
28
40
|
# [return] String
|
29
41
|
#
|
@@ -48,13 +60,21 @@ module RqrcodePngBin
|
|
48
60
|
OptionParser.new do |opt|
|
49
61
|
opt.version = VERSION
|
50
62
|
opt.banner = "Usage: rqrcode_png [option] string"
|
51
|
-
|
52
|
-
|
63
|
+
|
64
|
+
opt.on('-c', '--canvas CANVAS (ex 200x200)') {|v|
|
65
|
+
re = %r{\A([0-9]+)x([0-9]+)\z}
|
53
66
|
|
54
67
|
if v =~ re
|
55
|
-
@
|
68
|
+
@canvas = [$1.to_i, $2.to_i]
|
56
69
|
else
|
57
|
-
raise ArgumentError, "option
|
70
|
+
raise ArgumentError, "option canvas should match #{re}"
|
71
|
+
end
|
72
|
+
}
|
73
|
+
opt.on('-f', '--from-file FILE') {|v|
|
74
|
+
if File.exist?(v)
|
75
|
+
@file = v
|
76
|
+
else
|
77
|
+
raise ArgumentError, "file you specified '#{v}' does not exist"
|
58
78
|
end
|
59
79
|
}
|
60
80
|
opt.on('-l', '--level LEVEL (default m)') {|v|
|
@@ -66,13 +86,13 @@ module RqrcodePngBin
|
|
66
86
|
raise ArgumentError, "option level should be included #{options}"
|
67
87
|
end
|
68
88
|
}
|
69
|
-
opt.on('-
|
70
|
-
re = %r{\A
|
89
|
+
opt.on('-s', '--size SIZE (default 4)') {|v|
|
90
|
+
re = %r{\A[0-9]+\z}
|
71
91
|
|
72
92
|
if v =~ re
|
73
|
-
@
|
93
|
+
@size = v.to_i
|
74
94
|
else
|
75
|
-
raise ArgumentError, "option
|
95
|
+
raise ArgumentError, "option size should match #{re}"
|
76
96
|
end
|
77
97
|
}
|
78
98
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
3
|
+
module RqrcodePngBin
|
4
|
+
class FileReader
|
5
|
+
def initialize(file)
|
6
|
+
@file = open(file)
|
7
|
+
@pat = %r{\A([^\t]+)(?:\t([^\t]+))?\z}
|
8
|
+
|
9
|
+
@str = nil
|
10
|
+
@dest = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# [param] Proc block
|
15
|
+
#
|
16
|
+
def each(&block)
|
17
|
+
@file.each_line {|line|
|
18
|
+
split!(line.chomp)
|
19
|
+
block.call(@str, @dest)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# [param] String line
|
25
|
+
#
|
26
|
+
def split!(line)
|
27
|
+
@pat =~ line
|
28
|
+
|
29
|
+
@str = $1
|
30
|
+
@dest = $2 ? $2 : "#{CGI.escape($1)}.png"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/rqrcode_png_bin.rb
CHANGED
@@ -1,26 +1,43 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe RqrcodePngBin do
|
4
|
+
describe RqrcodePngBin::App do
|
5
5
|
def app(argv = [])
|
6
6
|
RqrcodePngBin::App.new(argv)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe '#parser' do
|
10
|
-
context '
|
10
|
+
context 'canvas' do
|
11
11
|
context 'nil' do
|
12
12
|
it {
|
13
|
-
expect(app.
|
13
|
+
expect(app.canvas).to be_nil
|
14
14
|
}
|
15
15
|
end
|
16
|
-
context '
|
16
|
+
context '200x200' do
|
17
17
|
it {
|
18
|
-
expect(app(%w(-
|
18
|
+
expect(app(%w(-c 200x200)).canvas).to be == [200, 200]
|
19
19
|
}
|
20
20
|
end
|
21
|
-
context '
|
21
|
+
context 'abc' do
|
22
22
|
it {
|
23
|
-
expect {app(%w(-
|
23
|
+
expect {app(%w(-c abc))}.to raise_error(ArgumentError)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'file' do
|
28
|
+
context 'nil' do
|
29
|
+
it {
|
30
|
+
expect(app.file).to be_nil
|
31
|
+
}
|
32
|
+
end
|
33
|
+
context 'file exist' do
|
34
|
+
it {
|
35
|
+
expect(app(['-f', __FILE__]).file).to be == __FILE__
|
36
|
+
}
|
37
|
+
end
|
38
|
+
context 'file not exist' do
|
39
|
+
it {
|
40
|
+
expect {app(%w(-f foo)).file}.to raise_error(ArgumentError)
|
24
41
|
}
|
25
42
|
end
|
26
43
|
end
|
@@ -41,20 +58,20 @@ describe RqrcodePngBin do
|
|
41
58
|
}
|
42
59
|
end
|
43
60
|
end
|
44
|
-
context '
|
61
|
+
context 'size' do
|
45
62
|
context 'nil' do
|
46
63
|
it {
|
47
|
-
expect(app.
|
64
|
+
expect(app.size).to be == 4
|
48
65
|
}
|
49
66
|
end
|
50
|
-
context '
|
67
|
+
context '5' do
|
51
68
|
it {
|
52
|
-
expect(app(%w(-
|
69
|
+
expect(app(%w(-s 5)).size).to be == 5
|
53
70
|
}
|
54
71
|
end
|
55
|
-
context '
|
72
|
+
context 'a' do
|
56
73
|
it {
|
57
|
-
expect {app(%w(-
|
74
|
+
expect {app(%w(-s a))}.to raise_error(ArgumentError)
|
58
75
|
}
|
59
76
|
end
|
60
77
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RqrcodePngBin::FileReader do
|
4
|
+
describe '#split!' do
|
5
|
+
let(:reader) {
|
6
|
+
RqrcodePngBin::FileReader.new(File.dirname(__FILE__) + '/support/dummy')
|
7
|
+
}
|
8
|
+
let(:str) {
|
9
|
+
reader.instance_variable_get('@str')
|
10
|
+
}
|
11
|
+
let(:dest) {
|
12
|
+
reader.instance_variable_get('@dest')
|
13
|
+
}
|
14
|
+
|
15
|
+
context 'only string without escape' do
|
16
|
+
before {
|
17
|
+
reader.split!('abc')
|
18
|
+
}
|
19
|
+
context '@str' do
|
20
|
+
it { expect(str).to be == 'abc' }
|
21
|
+
end
|
22
|
+
context '@dest' do
|
23
|
+
it { expect(dest).to be == 'abc.png' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'only string with escape' do
|
27
|
+
before {
|
28
|
+
reader.split!('http://github.com')
|
29
|
+
}
|
30
|
+
context '@str' do
|
31
|
+
it { expect(str).to be == 'http://github.com' }
|
32
|
+
end
|
33
|
+
context '@dest' do
|
34
|
+
it { expect(dest).to be == 'http%3A%2F%2Fgithub.com.png' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'string with filename' do
|
38
|
+
before {
|
39
|
+
reader.split!("str\tfilename")
|
40
|
+
}
|
41
|
+
context '@str' do
|
42
|
+
it { expect(str).to be == 'str' }
|
43
|
+
end
|
44
|
+
context '@dest' do
|
45
|
+
it { expect(dest).to be == 'filename' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/support/dummy
ADDED
File without changes
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wtnabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rqrcode_png
|
@@ -84,10 +84,13 @@ files:
|
|
84
84
|
- bin/rqrcode_png
|
85
85
|
- lib/rqrcode_png_bin.rb
|
86
86
|
- lib/rqrcode_png_bin/app.rb
|
87
|
+
- lib/rqrcode_png_bin/file_reader.rb
|
87
88
|
- lib/rqrcode_png_bin/version.rb
|
88
89
|
- rqrcode_png_bin.gemspec
|
89
|
-
- spec/
|
90
|
+
- spec/app_spec.rb
|
91
|
+
- spec/file_reader_spec.rb
|
90
92
|
- spec/spec_helper.rb
|
93
|
+
- spec/support/dummy
|
91
94
|
homepage: https://github.com/wtnabe/rqrcode_png_bin
|
92
95
|
licenses:
|
93
96
|
- BSD
|
@@ -113,5 +116,7 @@ signing_key:
|
|
113
116
|
specification_version: 4
|
114
117
|
summary: command line interface for rqrcode_png
|
115
118
|
test_files:
|
116
|
-
- spec/
|
119
|
+
- spec/app_spec.rb
|
120
|
+
- spec/file_reader_spec.rb
|
117
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/support/dummy
|