rqrcode_png_bin 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require "optparse"
2
- require "nkf"
3
2
 
4
3
  module RqrcodePngBin
5
4
  class App
@@ -10,10 +9,11 @@ module RqrcodePngBin
10
9
  @file = nil
11
10
  @level = :m
12
11
  @size = 4
12
+ @stdin = nil
13
13
 
14
14
  parser.parse!(@argv)
15
15
  end
16
- attr_reader :canvas, :file, :level, :size
16
+ attr_reader :canvas, :file, :level, :size, :stdin
17
17
 
18
18
  def run
19
19
  if file
@@ -30,17 +30,26 @@ module RqrcodePngBin
30
30
  end
31
31
 
32
32
  def generate_png(str)
33
- png = RQRCode::QRCode.new(str, opts).to_img
33
+ png = RQRCode::QRCode.new(encoded_str(str), opts).to_img
34
34
  png = png.resize(*canvas) if canvas
35
35
 
36
36
  png
37
37
  end
38
38
 
39
+ def encoded_str(str)
40
+ str.encode('SJIS').force_encoding('ASCII-8BIT')
41
+ end
42
+
39
43
  #
40
44
  # [return] String
41
45
  #
42
46
  def str
43
- str = @argv.first
47
+ if @argv.first
48
+ @argv.first
49
+ else
50
+ @stdin ||= $stdin.gets
51
+ stdin if stdin.size > 0
52
+ end
44
53
  end
45
54
 
46
55
  #
@@ -1,9 +1,7 @@
1
- require "cgi"
2
-
3
1
  module RqrcodePngBin
4
2
  class FileReader
5
3
  def initialize(file)
6
- @file = open(file)
4
+ @file = open(file, 'r:utf-8')
7
5
  @pat = %r{\A([^\t]+)(?:\t([^\t]+))?\z}
8
6
 
9
7
  @str = nil
@@ -16,7 +14,7 @@ module RqrcodePngBin
16
14
  def each(&block)
17
15
  @file.each_line {|line|
18
16
  split!(line.chomp)
19
- block.call(@str, @dest)
17
+ block.call(@str, @dest) if @str and @dest
20
18
  }
21
19
  end
22
20
 
@@ -27,7 +25,7 @@ module RqrcodePngBin
27
25
  @pat =~ line
28
26
 
29
27
  @str = $1
30
- @dest = $2 ? $2 : "#{CGI.escape($1)}.png"
28
+ @dest = $2 ? $2 : "#{$1.gsub(/\//, '%2F')}.png" if $1
31
29
  end
32
30
  end
33
31
  end
@@ -1,3 +1,3 @@
1
1
  module RqrcodePngBin
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'spec_helper'
2
3
 
3
4
  describe RqrcodePngBin::FileReader do
@@ -12,6 +13,17 @@ describe RqrcodePngBin::FileReader do
12
13
  reader.instance_variable_get('@dest')
13
14
  }
14
15
 
16
+ context 'empty' do
17
+ before {
18
+ reader.split!('')
19
+ }
20
+ context '@str' do
21
+ it { expect(str).to be_nil }
22
+ end
23
+ context '@dest' do
24
+ it { expect(dest).to be_nil }
25
+ end
26
+ end
15
27
  context 'only string without escape' do
16
28
  before {
17
29
  reader.split!('abc')
@@ -31,7 +43,7 @@ describe RqrcodePngBin::FileReader do
31
43
  it { expect(str).to be == 'http://github.com' }
32
44
  end
33
45
  context '@dest' do
34
- it { expect(dest).to be == 'http%3A%2F%2Fgithub.com.png' }
46
+ it { expect(dest).to be == 'http:%2F%2Fgithub.com.png' }
35
47
  end
36
48
  end
37
49
  context 'string with filename' do
@@ -45,5 +57,16 @@ describe RqrcodePngBin::FileReader do
45
57
  it { expect(dest).to be == 'filename' }
46
58
  end
47
59
  end
60
+ context 'japanese string' do
61
+ before {
62
+ reader.split!("日本/語")
63
+ }
64
+ context '@str' do
65
+ it { expect(str).to be == '日本/語' }
66
+ end
67
+ context '@dest' do
68
+ it { expect(dest).to be == '日本%2F語.png' }
69
+ end
70
+ end
48
71
  end
49
72
  end
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode_png_bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - wtnabe
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
12
+ date: 2014-11-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rqrcode_png
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,29 +46,33 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  description: command line interface for rqrcode_png
@@ -94,26 +103,33 @@ files:
94
103
  homepage: https://github.com/wtnabe/rqrcode_png_bin
95
104
  licenses:
96
105
  - BSD
97
- metadata: {}
98
106
  post_install_message:
99
107
  rdoc_options: []
100
108
  require_paths:
101
109
  - lib
102
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
103
112
  requirements:
104
- - - '>='
113
+ - - ! '>='
105
114
  - !ruby/object:Gem::Version
106
115
  version: '0'
116
+ segments:
117
+ - 0
118
+ hash: -1476981731966827747
107
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
108
121
  requirements:
109
- - - '>='
122
+ - - ! '>='
110
123
  - !ruby/object:Gem::Version
111
124
  version: '0'
125
+ segments:
126
+ - 0
127
+ hash: -1476981731966827747
112
128
  requirements: []
113
129
  rubyforge_project:
114
- rubygems_version: 2.0.3
130
+ rubygems_version: 1.8.23.2
115
131
  signing_key:
116
- specification_version: 4
132
+ specification_version: 3
117
133
  summary: command line interface for rqrcode_png
118
134
  test_files:
119
135
  - spec/app_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 3af632bfe45808e81abd4c88cfb19cd0cc842e87
4
- data.tar.gz: 49e8deddb8c9236ab199df2fb99de0d51b852b3c
5
- SHA512:
6
- metadata.gz: 25fb3ed536294faaab8a92c736cc0bfad2843721ffb35643862ebed21857b9aceafeefa349e52ef672d7c273320a2b2c84238c4730bb78725724692848a45f92
7
- data.tar.gz: df4057489ee9c0673b231bec9935b72ed3b0daf2c551f1c20c36fcdb69972263aced58090ef3b88f5eec28ec81c008d65e42326088d126e076fc0e099cae7283