polygonize 0.0.1 → 0.0.3
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.
- data/README.md +2 -2
- data/lib/polygonize/version.rb +1 -1
- data/lib/polygonize.rb +20 -19
- data/spec/polygonize_spec.rb +15 -14
- metadata +2 -2
data/README.md
CHANGED
data/lib/polygonize/version.rb
CHANGED
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
String.class_eval do
|
7
|
+
def coordinates
|
8
|
+
ar1 = []
|
9
|
+
ar2 = []
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
self.split(//).each do | char |
|
12
|
+
u = format("%x", char.unpack("U*")[0])
|
13
|
+
ar1 << u.scan(/../)
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
# 奇数の場合は "00" を追加して、偶数配列にする
|
17
|
+
ar1.flatten!
|
18
|
+
ar1 << "00" if ar1.flatten.size%2 == 1
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
25
|
+
ar2.join(" ")
|
26
|
+
end
|
27
|
+
end
|
27
28
|
end
|
data/spec/polygonize_spec.rb
CHANGED
@@ -6,40 +6,41 @@ include Polygonize
|
|
6
6
|
|
7
7
|
describe "Polygonize" do
|
8
8
|
context "空テキスト" do
|
9
|
-
it "
|
10
|
-
|
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 "
|
22
|
-
|
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 =
|
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
|
-
|
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
|
-
|
33
|
+
txt_e.coordinates.split(",")[1].should eql "0"
|
39
34
|
end
|
40
35
|
|
41
36
|
it "x = 0x78" do
|
42
|
-
|
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.
|
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-
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|