class Sudoku::Coordinate

Represents a cell coordinate in one dimension of the Sudoku grid.

Attributes

coordinate[R]

Public Class Methods

new(coordinate) click to toggle source

Will initialize this coordinate.

  • coordinate coordinate value, which must be in the 0-8 interval.

# File lib/sudoku/model/coordinate.rb, line 11
def initialize(coordinate)
  fail ArgumentError,
       "Coordinate value must be 0-8, value #{coordinate} given." unless
        coordinate_valid?(coordinate)

  @coordinate = coordinate.to_i
end
valid?(coordinate) click to toggle source

Will return true, if the given coordinate is between 0-8 interval, inclusive.

# File lib/sudoku/model/coordinate.rb, line 30
def self.valid?(coordinate)
  return true if coordinate >= 0 && coordinate < 9
  false
end

Public Instance Methods

<=>(other) click to toggle source

Compares this cooridnate with the other one.

# File lib/sudoku/model/coordinate.rb, line 50
def <=>(other)
  return @coordinate <=> other.coordinate if other.respond_to?(:coordinate)
  @coordinate <=> other.to_i
end
coordinate_valid?(coordinate) click to toggle source

Will check if given number can be used as the valid coordinate, which means, that it is a number in the interval 0-8 inclusive. True is returned if the coordinate is valid, false otherwise.

  • coordinate coordinate value to check

# File lib/sudoku/model/coordinate.rb, line 24
def coordinate_valid?(coordinate)
  Coordinate.valid?(coordinate)
end
eql?(other) click to toggle source

Will check, if the given element represents the same one-dimensional coordiante.

# File lib/sudoku/model/coordinate.rb, line 57
def eql?(other)
  @coordinate == other.to_i
end
to_i() click to toggle source

Will convert this coordinate to integer.

# File lib/sudoku/model/coordinate.rb, line 40
def to_i
  @coordinate
end
to_int() click to toggle source

Will convert this coordinate to integer.

# File lib/sudoku/model/coordinate.rb, line 45
def to_int
  to_i
end
to_s() click to toggle source
# File lib/sudoku/model/coordinate.rb, line 35
def to_s
  @coordinate.to_s
end