Class: Rchess::Coord

Inherits:
Object
  • Object
show all
Defined in:
lib/rchess/coord.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Coord

Returns a new instance of Coord.



5
6
7
8
# File 'lib/rchess/coord.rb', line 5

def initialize(h)
  self.x = h.fetch(:x){ raise ArgumentError.new("Please provide a value for key :x") }
  self.y = h.fetch(:y){ raise ArgumentError.new("Please provide a value for key :y") }
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/rchess/coord.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/rchess/coord.rb', line 3

def y
  @y
end

Instance Method Details

#apply_delta(delta) ⇒ Object



10
11
12
# File 'lib/rchess/coord.rb', line 10

def apply_delta(delta)
  Coord.new({ x: (self.x + delta[:x]), y: (self.y + delta[:y]) })
end

#to_hashObject



14
15
16
# File 'lib/rchess/coord.rb', line 14

def to_hash
  { x: self.x, y: self.y }
end