class Pitchcar::Pieces::Piece
Constants
- DIRECTIONS
Attributes
direction[RW]
type[RW]
x[RW]
y[RW]
Public Class Methods
first_from_string(piece_string)
click to toggle source
# 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
new(properties)
click to toggle source
# File lib/pieces/piece.rb, line 10 def initialize(properties) self.x = properties[:x] self.y = properties[:y] self.direction = properties[:direction] end
type_from_string(string)
click to toggle source
# File lib/pieces/piece.rb, line 20 def self.type_from_string(string) case string when 'S' Straight when 'L' Left when 'R' Right end end
Public Instance Methods
coordinate()
click to toggle source
# File lib/pieces/piece.rb, line 39 def coordinate { x: x, y: y } end
name()
click to toggle source
# File lib/pieces/piece.rb, line 35 def name self.class.name.split('::').last end
to_h()
click to toggle source
# 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
Private Instance Methods
east?()
click to toggle source
# File lib/pieces/piece.rb, line 57 def east? direction == DIRECTIONS[:EAST] end
north?()
click to toggle source
# File lib/pieces/piece.rb, line 45 def north? direction == DIRECTIONS[:NORTH] end
south?()
click to toggle source
# File lib/pieces/piece.rb, line 49 def south? direction == DIRECTIONS[:SOUTH] end
west?()
click to toggle source
# File lib/pieces/piece.rb, line 53 def west? direction == DIRECTIONS[:WEST] end