Class: Pitchcar::Pieces::Piece
- Inherits:
-
Object
- Object
- Pitchcar::Pieces::Piece
- Defined in:
- lib/pieces/piece.rb
Constant Summary collapse
- DIRECTIONS =
{ NORTH: 0, EAST: 1, WEST: 2, SOUTH: 3 }
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#type ⇒ Object
Returns the value of attribute type.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #coordinate ⇒ Object
-
#initialize(properties) ⇒ Piece
constructor
A new instance of Piece.
- #name ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(properties) ⇒ Piece
Returns a new instance of Piece.
10 11 12 13 14 |
# File 'lib/pieces/piece.rb', line 10 def initialize(properties) self.x = properties[:x] self.y = properties[:y] self.direction = properties[:direction] end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
8 9 10 |
# File 'lib/pieces/piece.rb', line 8 def direction @direction end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/pieces/piece.rb', line 8 def type @type end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/pieces/piece.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/pieces/piece.rb', line 8 def y @y end |
Class Method Details
.first_from_string(piece_string) ⇒ Object
16 17 18 |
# File 'lib/pieces/piece.rb', line 16 def self.first_from_string(piece_string) Pieces::Piece.type_from_string(piece_string).new(x: 0, y: 0, direction: DIRECTIONS[:SOUTH]) end |
Instance Method Details
#coordinate ⇒ Object
39 40 41 |
# File 'lib/pieces/piece.rb', line 39 def coordinate { x: x, y: y } end |
#name ⇒ Object
35 36 37 |
# File 'lib/pieces/piece.rb', line 35 def name self.class.name.split('::').last end |
#to_h ⇒ Object
31 32 33 |
# File 'lib/pieces/piece.rb', line 31 def to_h { x: x, y: y, type: name, direction_name: DIRECTIONS.key(direction).downcase, direction: direction } end |