flippy 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -1
- data/lib/flippy/version.rb +1 -1
- data/lib/flippy/vertical.rb +14 -2
- data/spec/vertical_spec.rb +34 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3772f4b9c48e0aaa2f6c9a52dce645f1cd1b9c89
|
4
|
+
data.tar.gz: 430e7340d4e14a41a7cbf82fa4a55adf3d3c89a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ce040a29b002d95a043d5de511d6e26c92e175ee8b287dab5914b0f93398d759000e72b9198060ab619e7f9918feb64a34a0fe31b7a817689bd18e08a3add7
|
7
|
+
data.tar.gz: ee2e4066224b148e329718bfff62dc0cb2cd81f8c9e226867700b83dc99c9ff582b508e041d9e21f81d8d8b3ca642f6324cce2a81c4308c27e2f61a678b3cc30
|
data/History.txt
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
== 0.1.0 / 2013-03-20
|
2
|
+
* Flippy#vertical accept horizontal part with '//' symbol
|
3
|
+
|
1
4
|
== 0.0.9 / 2013-03-19
|
2
|
-
* Change spec to delete spaces after punctuations
|
5
|
+
* Change spec to delete spaces after punctuations for Flippy#vertical
|
3
6
|
* Refactoring
|
4
7
|
|
5
8
|
== 0.0.7-8 / 2013-03-18
|
data/lib/flippy/version.rb
CHANGED
data/lib/flippy/vertical.rb
CHANGED
@@ -5,10 +5,22 @@ module Flippy::Vertical
|
|
5
5
|
v = "|¬∟↓→↑←॥:"
|
6
6
|
HV = (h + v)
|
7
7
|
VH = (v + h)
|
8
|
+
H_SEP = '//'
|
8
9
|
|
10
|
+
# Convert to left-right vertical writing style.
|
11
|
+
#
|
12
|
+
# "Hi\nFo".vertical => "F H "
|
13
|
+
# "o i "
|
14
|
+
#
|
15
|
+
# Last part after "//" symbol is taken as a normal writing part.
|
16
|
+
#
|
17
|
+
# "Hi\nFo//by me".vertical => "F H "
|
18
|
+
# "o i by me"
|
19
|
+
#
|
9
20
|
def vertical
|
10
21
|
lines = []
|
11
|
-
self.
|
22
|
+
v_part, _, h_part = self.rpartition(H_SEP).reject(&:empty?)
|
23
|
+
v_part.to_s.tr(HV, VH)
|
12
24
|
.each_line do |line|
|
13
25
|
main_line, punc_line = [], []
|
14
26
|
line.chomp.each_char.with_index do |chr, i|
|
@@ -25,6 +37,6 @@ module Flippy::Vertical
|
|
25
37
|
max = lines.map(&:size).max
|
26
38
|
lines.map { |line| line.fill(' ', line.size...max) }
|
27
39
|
.transpose
|
28
|
-
.map { |line| line.join.reverse }.join("\n")
|
40
|
+
.map { |line| line.join.reverse }.join("\n").concat("#{h_part}")
|
29
41
|
end
|
30
42
|
end
|
data/spec/vertical_spec.rb
CHANGED
@@ -24,6 +24,32 @@ EOS
|
|
24
24
|
ち
|
25
25
|
は
|
26
26
|
|、
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
context "vertical horizontal mix string" do
|
31
|
+
subject { "ニッポンの//自然".vertical }
|
32
|
+
it { should eq <<-EOS.chomp }
|
33
|
+
ニ
|
34
|
+
ッ
|
35
|
+
ポ
|
36
|
+
ン
|
37
|
+
の 自然
|
38
|
+
EOS
|
39
|
+
end
|
40
|
+
|
41
|
+
context "vertical horizontal mix string" do
|
42
|
+
subject { "ニッポンの//自然//大切に。".vertical }
|
43
|
+
it { should eq <<-EOS.chomp }
|
44
|
+
ニ
|
45
|
+
ッ
|
46
|
+
ポ
|
47
|
+
ン
|
48
|
+
の
|
49
|
+
/
|
50
|
+
/
|
51
|
+
自
|
52
|
+
然 大切に。
|
27
53
|
EOS
|
28
54
|
end
|
29
55
|
|
@@ -36,5 +62,13 @@ EOS
|
|
36
62
|
subject { "\n".vertical }
|
37
63
|
it { should eq "" }
|
38
64
|
end
|
65
|
+
|
66
|
+
context "immutable test" do
|
67
|
+
it "should be immutable" do
|
68
|
+
str = "こんにちは、\n日本。"
|
69
|
+
str.vertical
|
70
|
+
str.should eq "こんにちは、\n日本。"
|
71
|
+
end
|
72
|
+
end
|
39
73
|
end
|
40
74
|
end
|