lays 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/lib/lays/version.rb +1 -1
- data/lib/lays.rb +9 -5
- data/test/text_layers_test.rb +21 -5
- 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: fa165b0dfc65a1195a7219030c7b72f2ff19af7e
|
4
|
+
data.tar.gz: ddf9af5ca25cc4594bd9077ee55c90b6a4011fd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f1d692c83e10f5366de6aa0ce611b3d4b3d5b2be2c26155e1f672935524c8f42563ccc971ed48bb1fba36955a90a183d1d2f9e5d2e2b17c7198eeeac8174ad
|
7
|
+
data.tar.gz: c36bb27d8de37a8f885f170eb831f2d0d8bb837ab054fd9e2f200bc926af62cfe3de2a1ed3fddb13d22a01c07b51495721b0d29b4a56966dd245b17c62575d8b
|
data/.gitignore
CHANGED
data/lib/lays/version.rb
CHANGED
data/lib/lays.rb
CHANGED
@@ -10,21 +10,25 @@ module Lays
|
|
10
10
|
def [](layer)
|
11
11
|
layers[layer]
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def layers
|
15
15
|
@layer ||= {}
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_s
|
19
|
-
@result ||=
|
19
|
+
@result ||= render
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
result = []
|
20
24
|
layers.sort {|a, b| a[0] <=> b[0] }.each do |_, content|
|
21
25
|
content.split("\n").each_with_index.map do |line, i|
|
22
26
|
line.each_char.each_with_index do |c, j|
|
23
|
-
|
24
|
-
|
27
|
+
result[i] ||= []
|
28
|
+
result[i][j] = c unless c == nil || c == " "
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
28
|
-
|
32
|
+
result.map {|a|a.join}.join("\n")
|
29
33
|
end
|
30
34
|
end
|
data/test/text_layers_test.rb
CHANGED
@@ -37,15 +37,15 @@ end
|
|
37
37
|
|
38
38
|
test "two layers, one line, different size" do
|
39
39
|
frame = Frame.new
|
40
|
-
frame[
|
41
|
-
frame[
|
40
|
+
frame[2] = "123"
|
41
|
+
frame[5] = "abcdef"
|
42
42
|
assert_equal frame.to_s, "abcdef"
|
43
43
|
end
|
44
44
|
|
45
45
|
test "two layers, one line, different size" do
|
46
46
|
frame = Frame.new
|
47
|
-
frame[
|
48
|
-
frame[
|
47
|
+
frame[6] = "123"
|
48
|
+
frame[3] = "abcdef"
|
49
49
|
assert_equal frame.to_s, "123def"
|
50
50
|
end
|
51
51
|
|
@@ -73,7 +73,7 @@ TWO
|
|
73
73
|
111111
|
74
74
|
11111
|
75
75
|
ONE
|
76
|
-
|
76
|
+
|
77
77
|
res = <<RES.chomp
|
78
78
|
3231111
|
79
79
|
232121
|
@@ -81,3 +81,19 @@ ONE
|
|
81
81
|
RES
|
82
82
|
assert_equal frame.to_s, res
|
83
83
|
end
|
84
|
+
|
85
|
+
|
86
|
+
test "re-rendering frames" do
|
87
|
+
frame = Frame.new
|
88
|
+
frame[2] = "two"
|
89
|
+
frame[1] = "one"
|
90
|
+
frame.to_s
|
91
|
+
|
92
|
+
frame[2] = "* *"
|
93
|
+
frame.to_s
|
94
|
+
|
95
|
+
frame[8] = " #"
|
96
|
+
res = frame.to_s
|
97
|
+
|
98
|
+
assert_equal res, "*n*#"
|
99
|
+
end
|