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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed5c8316274a7aedf9a9b5ab17667f316ccb3815
4
- data.tar.gz: 5152312738f84aee8f4e449b9be9e49ef596a2d4
3
+ metadata.gz: 9fe10c55f4de6a59604905293be125ffb4633540
4
+ data.tar.gz: 3654af44b9d5d173f221320091eb39cbe39b598e
5
5
  SHA512:
6
- metadata.gz: 78be516211ab1103a6472ec7d6b8e0e7a68bbc6b636c4d1f7ee652e72b397e30e25b2c8f40736361ff9cb2b36177fa4a57f5da810543155f90aaaea41b4ed036
7
- data.tar.gz: 723644b6ddb3156f7267fe573c9cd7dd6a02a55fcef206eb27cba68170c8effd85727d4a6f367a4422b60c95ef4414ba792d620c58540b891634828ff6d47c02
6
+ metadata.gz: 26feb9917f37e12c86e33860c61bb277e15a4fd3078b3a5a3b9278148e0053a9730c5de3b5a9fd441da322a02f12e375d9dcb8688ce9b18bdbb7df7e70bf5586
7
+ data.tar.gz: cd4bf05ba6ee547b4dab2ef478744bb8733e98ce22c0a30a23f85039d9d6b2a8f75e4f10d23f982d9db3a804f4c0a67c81fd4939f32e51f96366485fda6b2404
data/.travis.yml CHANGED
@@ -5,4 +5,3 @@ rvm:
5
5
  - 2.1.1
6
6
  - 2.1.2
7
7
  - ruby-head
8
- - jruby-19mode
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("#{attr}=", val)
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 !transparent_char_for(layer, c)
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
@@ -1,3 +1,3 @@
1
1
  module Lays
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/test/lays_test.rb CHANGED
@@ -100,8 +100,20 @@ end
100
100
 
101
101
  scope do
102
102
  # width and height
103
- test "width" do
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.5
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-22 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler