Class: CellularMap::Zone
- Inherits:
-
Object
- Object
- CellularMap::Zone
- Includes:
- Enumerable
- Defined in:
- lib/cellular_map/zone.rb
Overview
Map zones
Zones are generated on the fly to provide a wrapper to keep a map’s zone under surveillance.
(see README for examples)
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Map the zone’s part of.
-
#x ⇒ Object
readonly
Zone’s boundaries.
-
#y ⇒ Object
readonly
Zone’s boundaries.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#[](x, y) ⇒ Object
Access to a cell inside the zone.
-
#[]=(x, y, content) ⇒ Object
Modification of a cell’s content inside the zone.
-
#each ⇒ Object
Iterating over each cells inside the zone.
-
#height ⇒ Object
Zone’s height.
-
#initialize(x, y, map) ⇒ Zone
constructor
:nodoc:.
-
#length ⇒ Object
Zone’s length.
-
#to_a ⇒ Object
Making an array of arrays of all cells inside the zone.
-
#width ⇒ Object
Zone’s width.
Constructor Details
#initialize(x, y, map) ⇒ Zone
:nodoc:
16 17 18 19 |
# File 'lib/cellular_map/zone.rb', line 16 def initialize(x, y, map) # :nodoc: @x, @y = rangeize(x, y) @map = map end |
Instance Attribute Details
#map ⇒ Object (readonly)
Map the zone’s part of
14 15 16 |
# File 'lib/cellular_map/zone.rb', line 14 def map @map end |
#x ⇒ Object (readonly)
Zone’s boundaries
12 13 14 |
# File 'lib/cellular_map/zone.rb', line 12 def x @x end |
#y ⇒ Object (readonly)
Zone’s boundaries
12 13 14 |
# File 'lib/cellular_map/zone.rb', line 12 def y @y end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/cellular_map/zone.rb', line 46 def ==(other) # :nodoc: ! self.detect { |c| ! (other.map[c.x, c.y].content == c.content) } end |
#[](x, y) ⇒ Object
Access to a cell inside the zone.
37 38 39 |
# File 'lib/cellular_map/zone.rb', line 37 def [](x, y) @map[*relative(x, y)] end |
#[]=(x, y, content) ⇒ Object
Modification of a cell’s content inside the zone.
42 43 44 |
# File 'lib/cellular_map/zone.rb', line 42 def []=(x, y, content) @map[*relative(x, y)] = content end |
#each ⇒ Object
Iterating over each cells inside the zone.
(first to last lines, first to last columns for each line)
53 54 55 56 |
# File 'lib/cellular_map/zone.rb', line 53 def each # :yields: cell @y.each { |y| @x.each { |x| yield Cell.new(x, y, @map) } } self end |
#height ⇒ Object
Zone’s height.
32 33 34 |
# File 'lib/cellular_map/zone.rb', line 32 def height @y.count end |
#length ⇒ Object
Zone’s length.
22 23 24 |
# File 'lib/cellular_map/zone.rb', line 22 def length width * height end |
#to_a ⇒ Object
Making an array of arrays of all cells inside the zone.
see each
61 62 63 |
# File 'lib/cellular_map/zone.rb', line 61 def to_a @y.collect { |y| @x.collect { |x| Cell.new(x, y, @map) } } end |
#width ⇒ Object
Zone’s width.
27 28 29 |
# File 'lib/cellular_map/zone.rb', line 27 def width @x.count end |