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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5439b43079d73905d206be9b4d37bd0a7293440
4
- data.tar.gz: 98e168c8c39e42363294888dd34911095b7f3de4
3
+ metadata.gz: fa165b0dfc65a1195a7219030c7b72f2ff19af7e
4
+ data.tar.gz: ddf9af5ca25cc4594bd9077ee55c90b6a4011fd3
5
5
  SHA512:
6
- metadata.gz: cd236c35af9b791cfe1dd69379bc5b7d55ba0583c886f458b466ab044b87a3a434292f694d73a2b5656815ee7b1a429d56dcf4704fc2c6487e9eb28dc3bbb563
7
- data.tar.gz: 38f48527e7db5e9556a58f553bfba342f5ef67c2d226747de0f46bf8479a2d95e0285a42df9452834fea78842ba628add52cebfb3f68c5d68cd5d66880489cb1
6
+ metadata.gz: b1f1d692c83e10f5366de6aa0ce611b3d4b3d5b2be2c26155e1f672935524c8f42563ccc971ed48bb1fba36955a90a183d1d2f9e5d2e2b17c7198eeeac8174ad
7
+ data.tar.gz: c36bb27d8de37a8f885f170eb831f2d0d8bb837ab054fd9e2f200bc926af62cfe3de2a1ed3fddb13d22a01c07b51495721b0d29b4a56966dd245b17c62575d8b
data/.gitignore CHANGED
@@ -9,7 +9,6 @@ _yardoc
9
9
  coverage
10
10
  doc/
11
11
  lib/bundler/man
12
- pkg
13
12
  rdoc
14
13
  spec/reports
15
14
  test/tmp
data/lib/lays/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lays
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- @result[i] ||= []
24
- @result[i][j] = c unless c == nil || c == " "
27
+ result[i] ||= []
28
+ result[i][j] = c unless c == nil || c == " "
25
29
  end
26
30
  end
27
31
  end
28
- @result.map {|a|a.join}.join("\n")
32
+ result.map {|a|a.join}.join("\n")
29
33
  end
30
34
  end
@@ -37,15 +37,15 @@ end
37
37
 
38
38
  test "two layers, one line, different size" do
39
39
  frame = Frame.new
40
- frame[1] = "123"
41
- frame[2] = "abcdef"
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[2] = "123"
48
- frame[1] = "abcdef"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti