hanoi-jane 0.2.0 → 0.2.1

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: 53bb5402aa446034d4307ad875c9ac4f5a1a104b
4
- data.tar.gz: 278ecba723e14b8f88ff862633dcc90c48dc985d
3
+ metadata.gz: 06e62c5a4e7ec717a18279751453e39469c3d42f
4
+ data.tar.gz: c71cbcd679a30a248911b9599669af6af6586341
5
5
  SHA512:
6
- metadata.gz: 77976b7bd533cfae55610fe7d28c52fe273a2afb2fbc60c1614dd7b08e52b990ea54ccc3ea9bdbad136f7757d3dae38cc0d5391a5be50215a3b82fcaaf1cebed
7
- data.tar.gz: f5e32d1adf55bfd68e8f6af17066d175660c50d73730e1d2ad57918b789a911acd1726df0c6cafb874ba6483021226f0c9a7ec8cc68dea657590fe96f692197a
6
+ metadata.gz: a0f41539d1b867578d6f41ae78dbbe65cae61ae9cca5173cf395b4c25a1163f5489ddee21905392b0801263f74382b0e4e199521452e1fd11b46ed1381eec458
7
+ data.tar.gz: f2d42d4e7ff7a7a58042c81041ae9d7a6069cabfa90ceaca5ce3a1e715642211a04ee91e0d151aed6a0ba5404aa70ebaf4f8f2c3ac4ceece2e51cf6dbfc4e360
data/lib/hanoi/jane.rb CHANGED
@@ -5,6 +5,7 @@ require 'hanoi/jane/version'
5
5
  require 'hanoi/jane/towers'
6
6
  require 'hanoi/jane/constrained_towers'
7
7
  require 'hanoi/jane/matrix'
8
+ require 'hanoi/jane/console'
8
9
 
9
10
  module Hanoi
10
11
  module Jane
@@ -0,0 +1,55 @@
1
+ module Hanoi
2
+ module Jane
3
+ class Console
4
+ attr_reader :content
5
+
6
+ def initialize towers
7
+ @stacks = towers.stacks
8
+ @discs = towers.discs
9
+ @content = ''
10
+ x = @stacks.clone
11
+ y = x.map { |s| s.clone }
12
+
13
+ (Console.rotate y.map { |s| (Console.pad s, @discs).reverse }).each do |stack|
14
+ @content += stack.map { |s| Console.make_disc s, (Console.scale @discs) }.join ' '
15
+ @content += "\n"
16
+ end
17
+ end
18
+
19
+ def to_s
20
+ @content
21
+ end
22
+
23
+ def Console.pad array, length
24
+ until array.length == length
25
+ array.push nil
26
+ end
27
+
28
+ array.reverse
29
+ end
30
+
31
+ def Console.make_disc width, space, char = 'o'
32
+ unless width
33
+ return ' ' * space
34
+ end
35
+
36
+ count = Console.scale width
37
+ padding = (space - count) / 2
38
+
39
+ '%s%s%s' % [
40
+ ' ' * padding,
41
+ char * count,
42
+ ' ' * padding
43
+ ]
44
+ end
45
+
46
+ def Console.scale size
47
+ (size * 2) + 1
48
+ end
49
+
50
+ def Console.rotate stacks
51
+ stacks.map { |s| s.clone }.transpose.reverse
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,7 +3,7 @@ module Hanoi
3
3
  class Towers
4
4
  include Enumerable
5
5
 
6
- attr_reader :total, :stacks
6
+ attr_reader :total, :stacks, :discs
7
7
 
8
8
  def initialize discs
9
9
  @discs = discs
@@ -27,16 +27,7 @@ module Hanoi
27
27
  end
28
28
 
29
29
  def console
30
- s = ''
31
- x = self.stacks.clone
32
- y = x.map { |s| s.clone }
33
-
34
- (Towers.rotate y.map { |s| (Towers.pad s, @discs).reverse }).each do |stack|
35
- s += stack.map { |s| Towers.make_disc s, (Towers.scale @discs) }.join ' '
36
- s += "\n"
37
- end
38
-
39
- s
30
+ (Console.new self).to_s
40
31
  end
41
32
 
42
33
  def inspect
@@ -112,37 +103,6 @@ module Hanoi
112
103
  def Towers.rebase value, base, width
113
104
  '%0*d' % [width, value.to_s(base)]
114
105
  end
115
-
116
- def Towers.pad array, length
117
- until array.length == length
118
- array.push nil
119
- end
120
-
121
- array.reverse
122
- end
123
-
124
- def Towers.make_disc width, space, char = 'o'
125
- unless width
126
- return ' ' * space
127
- end
128
-
129
- count = Towers.scale width
130
- padding = (space - count) / 2
131
-
132
- '%s%s%s' % [
133
- ' ' * padding,
134
- char * count,
135
- ' ' * padding
136
- ]
137
- end
138
-
139
- def Towers.scale size
140
- (size * 2) + 1
141
- end
142
-
143
- def Towers.rotate stacks
144
- stacks.map { |s| s.clone }.transpose.reverse
145
- end
146
106
  end
147
107
  end
148
108
  end
@@ -1,5 +1,5 @@
1
1
  module Hanoi
2
2
  module Jane
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanoi-jane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -147,6 +147,7 @@ files:
147
147
  - hanoi-jane.gemspec
148
148
  - lib/hanoi/jane.rb
149
149
  - lib/hanoi/jane/cli.rb
150
+ - lib/hanoi/jane/console.rb
150
151
  - lib/hanoi/jane/constrained_towers.rb
151
152
  - lib/hanoi/jane/matrix.rb
152
153
  - lib/hanoi/jane/towers.rb