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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0f8ff229a6f20aac5756a3122d51847238cb654
4
- data.tar.gz: d47628a5cdfe439f30cbe59c964aea9f01ffe8b9
3
+ metadata.gz: 35d0f3e98c337744e7f1d1776b09c7dc7df644ac
4
+ data.tar.gz: bcdc8b9dbfd285254cfe14b859b403c90aeb78ba
5
5
  SHA512:
6
- metadata.gz: c423f41ddcb779269309a091582f9e573c3ffd4aa514dde9de51cd97aa902fc018f282a8095f7e855b1a3427ef9094f8a033f4abca578b0bbfefcf4d5994b3f3
7
- data.tar.gz: 591891b01d827562c74dc27e7d6e9a9adcf8baf254d41522ba3c3c2a1333a5d18f3e5018b36fb5f898953e55e762670f7379230414dc14d99b727912fa127f92
6
+ metadata.gz: a529726fcded12f0282f79b4136685f5c014124434b5115b20d60c4805cbfb3ec03262061a356c8447a2baf377ef2016c376107620bd12ba652af6a4408b5b62
7
+ data.tar.gz: 5923bd721488725915dda09dcad3d7ed8b6d47c4c178fc0f422c26af419bec40a8bde15320d57aa903bb67667484156de1353e915a42d1a1e734aa28046b78a0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Lifelike
2
2
 
3
+ [![Gem
4
+ Version](https://badge.fury.io/rb/lifelike.svg)](http://badge.fury.io/rb/lifelike)
3
5
  [![Build
4
6
  Status](https://travis-ci.org/mxhold/lifelike.svg?branch=master)](https://travis-ci.org/mxhold/lifelike)
5
7
  [![Code
@@ -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[:rules]})"
46
+ "(default: #{default_options[:rule_string]})"
47
47
  ) do |rule_string|
48
48
  @options[:rule_string] = rule_string
49
49
  end
@@ -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
- @rows.map do |row|
32
- row.map do |cell|
33
- yield(cell)
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
@@ -1,3 +1,3 @@
1
1
  module Lifelike
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
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.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-15 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler