lays 0.0.5 → 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/.travis.yml +0 -1
- data/lib/lays.rb +29 -3
- data/lib/lays/version.rb +1 -1
- data/test/lays_test.rb +92 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe10c55f4de6a59604905293be125ffb4633540
|
4
|
+
data.tar.gz: 3654af44b9d5d173f221320091eb39cbe39b598e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26feb9917f37e12c86e33860c61bb277e15a4fd3078b3a5a3b9278148e0053a9730c5de3b5a9fd441da322a02f12e375d9dcb8688ce9b18bdbb7df7e70bf5586
|
7
|
+
data.tar.gz: cd4bf05ba6ee547b4dab2ef478744bb8733e98ce22c0a30a23f85039d9d6b2a8f75e4f10d23f982d9db3a804f4c0a67c81fd4939f32e51f96366485fda6b2404
|
data/.travis.yml
CHANGED
data/lib/lays.rb
CHANGED
@@ -3,10 +3,10 @@ require "ostruct"
|
|
3
3
|
|
4
4
|
module Lays
|
5
5
|
|
6
|
-
Layer = Struct.new(:content, :transparent_char) do
|
6
|
+
Layer = Struct.new(:content, :transparent_char, :space_char) do
|
7
7
|
def initialize(attrs={})
|
8
8
|
attrs.each do |attr, val|
|
9
|
-
self.send("
|
9
|
+
self.send("self.#{attr}=", val)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -42,7 +42,9 @@ module Lays
|
|
42
42
|
content.split("\n").each_with_index.map do |line, i|
|
43
43
|
line.each_char.each_with_index do |c, j|
|
44
44
|
result[i] ||= []
|
45
|
-
if
|
45
|
+
if space_char_for(layer, c)
|
46
|
+
result[i][j] = " "
|
47
|
+
elsif !transparent_char_for(layer, c)
|
46
48
|
result[i][j] = c
|
47
49
|
elsif key == lays.first.first
|
48
50
|
result[i][j] = " "
|
@@ -53,8 +55,19 @@ module Lays
|
|
53
55
|
result.map {|a|a.join}.join("\n")
|
54
56
|
end
|
55
57
|
|
58
|
+
def height
|
59
|
+
layers.count
|
60
|
+
end
|
61
|
+
|
62
|
+
def width
|
63
|
+
layers.max { |a, b|
|
64
|
+
a.last.content.size <=> b.last.content.size
|
65
|
+
}.last.content.size
|
66
|
+
end
|
67
|
+
|
56
68
|
def transparent_char=(char)
|
57
69
|
@transparent_char = char
|
70
|
+
@space_char = nil
|
58
71
|
end
|
59
72
|
|
60
73
|
def transparent_char
|
@@ -65,4 +78,17 @@ module Lays
|
|
65
78
|
transparent = layer.transparent_char || transparent_char
|
66
79
|
char == transparent
|
67
80
|
end
|
81
|
+
|
82
|
+
def space_char=(char)
|
83
|
+
@space_char = char
|
84
|
+
@transparent_char = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def space_char
|
88
|
+
@space_char
|
89
|
+
end
|
90
|
+
|
91
|
+
def space_char_for(layer, char)
|
92
|
+
char == layer.space_char || char == space_char
|
93
|
+
end
|
68
94
|
end
|
data/lib/lays/version.rb
CHANGED
data/test/lays_test.rb
CHANGED
@@ -100,8 +100,20 @@ end
|
|
100
100
|
|
101
101
|
scope do
|
102
102
|
# width and height
|
103
|
-
|
103
|
+
setup do
|
104
|
+
frame = Frame.new
|
105
|
+
frame[3] = "a"
|
106
|
+
frame[2] = "bcde"
|
107
|
+
frame[1] = "fg"
|
108
|
+
frame
|
109
|
+
end
|
110
|
+
|
111
|
+
test "width" do |frame|
|
112
|
+
assert_equal frame.width, 4
|
113
|
+
end
|
104
114
|
|
115
|
+
test "height" do |frame|
|
116
|
+
assert_equal frame.height, 3
|
105
117
|
end
|
106
118
|
end
|
107
119
|
|
@@ -150,3 +162,82 @@ scope do
|
|
150
162
|
end
|
151
163
|
|
152
164
|
end
|
165
|
+
|
166
|
+
scope do
|
167
|
+
# Space
|
168
|
+
test "space char" do
|
169
|
+
frame = Frame.new
|
170
|
+
|
171
|
+
frame[6] = "0=0 0"
|
172
|
+
frame[6].space_char = "="
|
173
|
+
frame[3] = "11111"
|
174
|
+
assert_equal frame.to_s, "0 010"
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
test "setting space char beforehand" do
|
179
|
+
frame = Frame.new
|
180
|
+
|
181
|
+
frame[6].space_char = "#"
|
182
|
+
frame[6] = "2 # 2"
|
183
|
+
frame[3] = "11111"
|
184
|
+
assert_equal frame.to_s, "21 12"
|
185
|
+
end
|
186
|
+
|
187
|
+
test "setting global space char for frame" do
|
188
|
+
frame = Frame.new
|
189
|
+
frame.space_char = "$"
|
190
|
+
|
191
|
+
frame[6] = "2 $ 2"
|
192
|
+
frame[3] = "11111"
|
193
|
+
assert_equal frame.to_s, "21 12"
|
194
|
+
end
|
195
|
+
|
196
|
+
test "full space example" do
|
197
|
+
frame = Frame.new
|
198
|
+
frame.space_char = "$"
|
199
|
+
|
200
|
+
frame[9].space_char = "*"
|
201
|
+
frame[6].space_char = "%"
|
202
|
+
|
203
|
+
frame[9] = "3**$***3 "
|
204
|
+
frame[6] = "22%2$%%2 "
|
205
|
+
frame[3] = "11111$$1 "
|
206
|
+
frame[1] = "000000$00"
|
207
|
+
assert_equal frame.to_s, "3 30"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
scope do
|
212
|
+
test "Space and Transparency" do
|
213
|
+
frame = Frame.new
|
214
|
+
frame.space_char = "-"
|
215
|
+
frame.transparent_char = "."
|
216
|
+
|
217
|
+
|
218
|
+
frame[9].space_char = "_"
|
219
|
+
frame[6].transparent_char = ","
|
220
|
+
|
221
|
+
frame[9] = "3 .,..-_. "
|
222
|
+
frame[6] = "2222,,22--"
|
223
|
+
frame[3] = "11111.1111"
|
224
|
+
frame[1] = "0000000000"
|
225
|
+
assert_equal frame.to_s, "3 2,10- - "
|
226
|
+
end
|
227
|
+
|
228
|
+
test "Space and Transparency" do
|
229
|
+
frame = Frame.new
|
230
|
+
frame.transparent_char = "."
|
231
|
+
frame.space_char = "-"
|
232
|
+
|
233
|
+
|
234
|
+
frame[6].transparent_char = ","
|
235
|
+
frame[9].space_char = "_"
|
236
|
+
|
237
|
+
frame[9] = "3 .,..-_. "
|
238
|
+
frame[6] = "2222,,22--"
|
239
|
+
frame[3] = "11111.1111"
|
240
|
+
frame[1] = "0000000000"
|
241
|
+
assert_equal frame.to_s, "32.,.. . "
|
242
|
+
end
|
243
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|