polygonize 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,8 +19,8 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  include Polygonize
22
- coordinates( TEXT )
23
- # => {"points" => "x1,y1 x2,y2 x3,y3.....", "text" => "ORIGINAL_TEXT"}
22
+ ORIGINAL_TEXT.coordinates
23
+ # => "x1,y1 x2,y2 x3,y3....."
24
24
 
25
25
  ## Contributing
26
26
 
@@ -1,3 +1,3 @@
1
1
  module Polygonize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/polygonize.rb CHANGED
@@ -1,27 +1,28 @@
1
+ # encoding: UTF-8
2
+
1
3
  require "polygonize/version"
2
4
 
3
5
  module Polygonize
4
- def coordinates(txt)
5
- ar1 = []
6
- ar2 = []
7
- ret = {}
6
+ String.class_eval do
7
+ def coordinates
8
+ ar1 = []
9
+ ar2 = []
8
10
 
9
- txt.split(//).each do | char |
10
- u = format("%x", char.unpack("U*")[0])
11
- ar1 << u.scan(/../)
12
- end
11
+ self.split(//).each do | char |
12
+ u = format("%x", char.unpack("U*")[0])
13
+ ar1 << u.scan(/../)
14
+ end
13
15
 
14
- # 奇数の場合は "00" を追加して、偶数配列にする
15
- ar1.flatten!
16
- ar1 << "00" if ar1.flatten.size%2 == 1
16
+ # 奇数の場合は "00" を追加して、偶数配列にする
17
+ ar1.flatten!
18
+ ar1 << "00" if ar1.flatten.size%2 == 1
17
19
 
18
- ar1.each_slice(2) do | a,b |
19
- ar2 << [a, b].map! { |c| c.hex }.join(",")
20
- end
20
+ # Max 255 で座標の文字列を生成
21
+ ar1.each_slice(2) do | a,b |
22
+ ar2 << [a, b].map! { |c| c.hex }.join(",")
23
+ end
21
24
 
22
- ret['points'] = ar2.join(" ")
23
- ret['text'] = txt
24
- ret
25
- end
26
-
25
+ ar2.join(" ")
26
+ end
27
+ end
27
28
  end
@@ -6,40 +6,41 @@ include Polygonize
6
6
 
7
7
  describe "Polygonize" do
8
8
  context "空テキスト" do
9
- it "空テキストはreturn[point]に何も返さない" do
10
- coordinates("")['points'].should eql ""
9
+ it "空テキストは何も返さない" do
10
+ "".coordinates.should eql ""
11
11
  end
12
-
13
- it "空テキストはreturn[text]に何も返さない" do
14
- coordinates("")['text'].should eql ""
15
- end
16
-
17
12
  end
18
13
 
19
14
  context "テキスト" do
20
15
  txt = "こんにちは"
21
- it "return[text] は元の文章を返す" do
22
- coordinates(txt)['text'].should eql txt
16
+ it "はxy座標の文字列を返す" do
17
+ txt.coordinates.should eql "48,83 48,147 48,107 48,97 48,111"
23
18
  end
24
-
19
+
25
20
  it "要素は偶数個である" do
26
- ar = coordinates(txt)['points'].split(" ").inject([]) { |mem, x| mem << x.split(",") }
21
+ ar = txt.coordinates.split(" ").inject([]) { |mem, x| mem << x.split(",") }
27
22
  (ar.flatten.size%2).should eql 0
28
23
  end
29
24
 
30
25
  it "各要素は255(FF)以下である" do
31
- coordinates(txt)['points'].split(" ").flatten.reject! { |x| x.to_i < 255}
26
+ txt.coordinates.split(" ").flatten.reject! { |x| x.to_i < 255}
32
27
  end
33
28
  end
34
29
 
35
30
  context "1バイトテキスト" do
36
31
  txt_e = "x"
37
32
  it "ゼロで補完する" do
38
- coordinates(txt_e)['points'].split(",")[1].should eql "0"
33
+ txt_e.coordinates.split(",")[1].should eql "0"
39
34
  end
40
35
 
41
36
  it "x = 0x78" do
42
- coordinates(txt_e)['points'].split(",")[0].should eql "78".hex.to_s
37
+ txt_e.coordinates.split(",")[0].should eql "78".hex.to_s
38
+ end
39
+ end
40
+
41
+ context "メソッド" do
42
+ it "coordinatesは Stringのインスタンスメソッドがある" do
43
+ String.instance_methods.grep(/^coordinates/).should eql [:coordinates]
43
44
  end
44
45
  end
45
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polygonize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-04 00:00:00.000000000 Z
12
+ date: 2012-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec