lifelike 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/lifelike/cli/options.rb +3 -3
- data/lib/lifelike/grid.rb +35 -18
- data/lib/lifelike/version.rb +1 -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: 35d0f3e98c337744e7f1d1776b09c7dc7df644ac
|
4
|
+
data.tar.gz: bcdc8b9dbfd285254cfe14b859b403c90aeb78ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a529726fcded12f0282f79b4136685f5c014124434b5115b20d60c4805cbfb3ec03262061a356c8447a2baf377ef2016c376107620bd12ba652af6a4408b5b62
|
7
|
+
data.tar.gz: 5923bd721488725915dda09dcad3d7ed8b6d47c4c178fc0f422c26af419bec40a8bde15320d57aa903bb67667484156de1353e915a42d1a1e734aa28046b78a0
|
data/README.md
CHANGED
data/lib/lifelike/cli/options.rb
CHANGED
@@ -33,8 +33,8 @@ module Lifelike
|
|
33
33
|
opts.on(
|
34
34
|
'-c [iterations]',
|
35
35
|
'--count [iterations]',
|
36
|
-
'Number of iterations to perform' \
|
37
|
-
"(default #{default_options[:generations]})"
|
36
|
+
'Number of iterations to perform ' \
|
37
|
+
"(default: #{default_options[:generations]})"
|
38
38
|
) do |c|
|
39
39
|
@options[:generations] = c.to_i
|
40
40
|
end
|
@@ -43,7 +43,7 @@ module Lifelike
|
|
43
43
|
'-r [rule_string]',
|
44
44
|
'--rules [rule_string]',
|
45
45
|
'Rules for the life-like cellular automaton ' \
|
46
|
-
"(default #{default_options[:
|
46
|
+
"(default: #{default_options[:rule_string]})"
|
47
47
|
) do |rule_string|
|
48
48
|
@options[:rule_string] = rule_string
|
49
49
|
end
|
data/lib/lifelike/grid.rb
CHANGED
@@ -1,22 +1,9 @@
|
|
1
1
|
module Lifelike
|
2
2
|
class Grid
|
3
|
-
ROW_DELIMITER = "\n"
|
4
|
-
CELL_DELIMITER = ''
|
5
|
-
|
6
3
|
def initialize(rows)
|
7
4
|
@rows = rows
|
8
5
|
end
|
9
6
|
|
10
|
-
def self.from_s(string)
|
11
|
-
new(
|
12
|
-
string.split(ROW_DELIMITER).map do |row_string|
|
13
|
-
row_string.split(CELL_DELIMITER).map do |char|
|
14
|
-
yield(char)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
7
|
def map_with_neighbors
|
21
8
|
self.class.new(
|
22
9
|
@rows.map.with_index do |row, row_index|
|
@@ -27,12 +14,20 @@ module Lifelike
|
|
27
14
|
)
|
28
15
|
end
|
29
16
|
|
17
|
+
def to_a
|
18
|
+
@rows
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_s(string)
|
22
|
+
GridSerializer.load(string) do |char|
|
23
|
+
yield(char)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
30
27
|
def to_s
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end.join(CELL_DELIMITER)
|
35
|
-
end.join(ROW_DELIMITER)
|
28
|
+
GridSerializer.dump(self) do |cell|
|
29
|
+
yield(cell)
|
30
|
+
end
|
36
31
|
end
|
37
32
|
|
38
33
|
private
|
@@ -56,5 +51,27 @@ module Lifelike
|
|
56
51
|
def nonwrapping_fetch(row_index, col_index)
|
57
52
|
@rows.fetch(row_index, [])[col_index] if row_index >= 0 && col_index >= 0
|
58
53
|
end
|
54
|
+
|
55
|
+
class GridSerializer
|
56
|
+
ROW_DELIMITER = "\n"
|
57
|
+
CELL_DELIMITER = ''
|
58
|
+
def self.load(string)
|
59
|
+
Grid.new(
|
60
|
+
string.split(ROW_DELIMITER).map do |row_string|
|
61
|
+
row_string.split(CELL_DELIMITER).map do |char|
|
62
|
+
yield(char)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.dump(grid)
|
69
|
+
grid.to_a.map do |row|
|
70
|
+
row.map do |cell|
|
71
|
+
yield(cell)
|
72
|
+
end.join(CELL_DELIMITER)
|
73
|
+
end.join(ROW_DELIMITER)
|
74
|
+
end
|
75
|
+
end
|
59
76
|
end
|
60
77
|
end
|
data/lib/lifelike/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifelike
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Holder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|