cellular_map 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake'
2
-
2
+
3
3
  begin
4
4
  require 'jeweler'
5
5
  include_file_globs = ["README*",
@@ -24,13 +24,13 @@ begin
24
24
  gem.has_rdoc = true
25
25
  gem.extra_rdoc_files = ["README*"]
26
26
  gem.rdoc_options << '--line-numbers' << '--inline-source'
27
- gem.add_development_dependency("thoughtbot-shoulda", ">= 0")
27
+ gem.add_development_dependency("shoulda", ">= 0")
28
28
  end
29
29
  Jeweler::GemcutterTasks.new
30
30
  rescue LoadError
31
31
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
32
32
  end
33
-
33
+
34
34
  require 'rake/testtask'
35
35
  desc 'Test the cellular map gem.'
36
36
  Rake::TestTask.new(:test) do |t|
@@ -56,7 +56,7 @@ end
56
56
  task :test => :check_dependencies
57
57
 
58
58
  task :default => :test
59
-
59
+
60
60
  require 'rake/rdoctask'
61
61
  desc 'Generate documentation for the cellular map gem.'
62
62
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -3,7 +3,7 @@ require 'cellular_map/zone'
3
3
 
4
4
  module CellularMap
5
5
  # =Map
6
- #
6
+ #
7
7
  # Maps are limitless, only non-empty (nil content) cells are actually stored.
8
8
  #
9
9
  # (see README for examples)
@@ -40,6 +40,11 @@ module CellularMap
40
40
  self
41
41
  end
42
42
 
43
+ # Collecting all filled cells
44
+ def collect # :yields: cell
45
+ @store.keys.collect { |k| yield Cell.new(*(k + [self])) }
46
+ end
47
+
43
48
  # Converts to map to an array of filled cells
44
49
  def to_a
45
50
  @store.keys.collect { |k| Cell.new(*(k + [self])) }
@@ -6,7 +6,7 @@ module CellularMap
6
6
  #
7
7
  # (see README for examples)
8
8
  class Zone
9
-
9
+
10
10
  # Zone's boundaries
11
11
  attr_reader :x, :y
12
12
  # Map the zone's part of
@@ -16,7 +16,7 @@ module CellularMap
16
16
  @x, @y = rangeize(x, y)
17
17
  @map = map
18
18
  end
19
-
19
+
20
20
  # Zone's length.
21
21
  def length
22
22
  width * height
@@ -53,9 +53,16 @@ module CellularMap
53
53
  @y.each { |y| @x.each { |x| yield Cell.new(x, y, @map) } }
54
54
  end
55
55
 
56
+ # Collecting cells inside the zone.
57
+ #
58
+ # see each
59
+ def collect # :yields: cell
60
+ @y.inject([]) { |r, y| r + @x.collect { |x| yield Cell.new(x, y, @map) } }
61
+ end
62
+
56
63
  # Making an array of arrays of all cells inside the zone.
57
64
  #
58
- # (first to last lines, first to last columns for each line)
65
+ # see each
59
66
  def to_a
60
67
  @y.collect { |y| @x.collect { |x| Cell.new(x, y, @map) } }
61
68
  end
data/test/test_map.rb CHANGED
@@ -43,6 +43,12 @@ class TestMap < Test::Unit::TestCase
43
43
  assert_equal @map, result
44
44
  }
45
45
 
46
+ should("collect all filled cells") {
47
+ expected = @sample.collect { |c, v| c + [v] }.sort!
48
+ inside = @map.collect { |cell| [cell.x, cell.y, cell.content] }.sort!
49
+ assert_equal expected, inside
50
+ }
51
+
46
52
  should("be convertible to an array of cells") {
47
53
  res = @map.to_a
48
54
  assert res.is_a? Array
data/test/test_zone.rb CHANGED
@@ -59,6 +59,12 @@ class TestZone < Test::Unit::TestCase
59
59
  assert_equal @positions, inside
60
60
  }
61
61
 
62
+ should("collect all its cells in a basic one-dimension array") {
63
+ inside = @zone.collect { |cell| [cell.x, cell.y, cell.content] }.sort!
64
+ outside = @positions.collect { |x, y| [x, y, @sample[[x, y]]] }.sort!
65
+ assert_equal outside, inside
66
+ }
67
+
62
68
  should("be convertible to an array of all its cells") {
63
69
  res = @zone.to_a
64
70
  assert res.is_a? Array
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cellular_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Belleville
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 +01:00
12
+ date: 2010-01-29 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: thoughtbot-shoulda
16
+ name: shoulda
17
17
  type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement