Class: CellularMap::Cell
- Inherits:
-
Object
- Object
- CellularMap::Cell
- Defined in:
- lib/cellular_map/cell.rb
Overview
Map cells
Cells are generated on the fly to provide a wrapper to access to the map’s content in a more user-friendly way.
(see README for examples)
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Map the cell’s a part of.
-
#x ⇒ Object
readonly
Cell’s coordinates.
-
#y ⇒ Object
readonly
Cell’s coordinates.
Instance Method Summary collapse
-
#+(vector) ⇒ Object
Selecting a related cell through a vector movement.
-
#-(vector) ⇒ Object
Selecting a related cell through a vector movement.
-
#<=>(other) ⇒ Object
:nodoc:.
-
#==(other) ⇒ Object
:nodoc:.
-
#content ⇒ Object
Cell’s content.
-
#content=(content) ⇒ Object
Setting new content in the cell.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(x, y, map) ⇒ Cell
constructor
:nodoc:.
Constructor Details
#initialize(x, y, map) ⇒ Cell
:nodoc:
15 16 17 18 19 |
# File 'lib/cellular_map/cell.rb', line 15 def initialize(x, y, map) # :nodoc: @x = x.to_i @y = y.to_i @map = map end |
Instance Attribute Details
#map ⇒ Object (readonly)
Map the cell’s a part of.
13 14 15 |
# File 'lib/cellular_map/cell.rb', line 13 def map @map end |
#x ⇒ Object (readonly)
Cell’s coordinates.
11 12 13 |
# File 'lib/cellular_map/cell.rb', line 11 def x @x end |
#y ⇒ Object (readonly)
Cell’s coordinates.
11 12 13 |
# File 'lib/cellular_map/cell.rb', line 11 def y @y end |
Instance Method Details
#+(vector) ⇒ Object
Selecting a related cell through a vector movement.
49 50 51 |
# File 'lib/cellular_map/cell.rb', line 49 def +(vector) @map[@x + vector.first, @y + vector.last] end |
#-(vector) ⇒ Object
Selecting a related cell through a vector movement.
54 55 56 |
# File 'lib/cellular_map/cell.rb', line 54 def -(vector) self + vector.collect { |v| -v } end |
#<=>(other) ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/cellular_map/cell.rb', line 40 def <=>(other) # :nodoc: 2 * (y <=> other.y) + (x <=> other.x) end |
#==(other) ⇒ Object
:nodoc:
35 36 37 38 |
# File 'lib/cellular_map/cell.rb', line 35 def ==(other) # :nodoc: self.class == other.class && [@x, @y, @map] == [other.x, other.y, other.map] end |
#content ⇒ Object
Cell’s content.
22 23 24 |
# File 'lib/cellular_map/cell.rb', line 22 def content @map.store[[x, y]] end |
#content=(content) ⇒ Object
Setting new content in the cell.
27 28 29 |
# File 'lib/cellular_map/cell.rb', line 27 def content=(content) @map[@x, @y] = content end |
#eql?(other) ⇒ Boolean
:nodoc:
44 45 46 |
# File 'lib/cellular_map/cell.rb', line 44 def eql?(other) # :nodoc: self == other end |
#hash ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/cellular_map/cell.rb', line 31 def hash # :nodoc: x + y end |