Module: Sashite::Cell

Defined in:
lib/sashite/cell.rb,
lib/sashite/cell/parser.rb,
lib/sashite/cell/constants.rb,
lib/sashite/cell/formatter.rb,
lib/sashite/cell/coordinate.rb,
lib/sashite/cell/errors/argument.rb,
lib/sashite/cell/errors/argument/messages.rb

Overview

CELL (Coordinate Encoding for Layered Locations) implementation.

Provides parsing, formatting, and validation of CELL coordinates for multi-dimensional game boards (up to 3 dimensions).

Examples:

Parsing a coordinate

coord = Sashite::Cell.parse("e4")
coord.indices    # => [4, 3]
coord.dimensions # => 2

Formatting indices

Sashite::Cell.format(4, 3) # => "e4"

Validation

Sashite::Cell.valid?("e4") # => true
Sashite::Cell.valid?("a0") # => false

See Also:

Defined Under Namespace

Modules: Constants, Errors, Formatter, Parser Classes: Coordinate

Class Method Summary collapse

Class Method Details

.format(*indices) ⇒ String

Formats indices into a CELL string.

Examples:

Sashite::Cell.format(4, 3)    # => "e4"
Sashite::Cell.format(0, 0, 0) # => "a1A"

Parameters:

  • indices (Array<Integer>)

    0-indexed coordinate values (0-255)

Returns:

  • (String)

    CELL coordinate string

Raises:



51
52
53
# File 'lib/sashite/cell.rb', line 51

def self.format(*indices)
  Coordinate.new(*indices).to_s
end

.parse(string) ⇒ Coordinate

Parses a CELL string into a Coordinate.

Examples:

Sashite::Cell.parse("e4")  # => #<Sashite::Cell::Coordinate e4>
Sashite::Cell.parse("a1A") # => #<Sashite::Cell::Coordinate a1A>
Sashite::Cell.parse("a0")  # => raises Sashite::Cell::Errors::Argument

Parameters:

  • string (String)

    CELL coordinate string

Returns:

Raises:



38
39
40
# File 'lib/sashite/cell.rb', line 38

def self.parse(string)
  Coordinate.new(*Parser.parse_to_indices(string))
end

.valid?(string) ⇒ Boolean

Reports whether string is a valid CELL coordinate.

Examples:

Sashite::Cell.valid?("e4")  # => true
Sashite::Cell.valid?("a0")  # => false

Parameters:

  • string (String)

    CELL coordinate string

Returns:

  • (Boolean)

    true if valid, false otherwise



77
78
79
80
81
82
# File 'lib/sashite/cell.rb', line 77

def self.valid?(string)
  validate(string)
  true
rescue Errors::Argument
  false
end

.validate(string) ⇒ nil

Validates a CELL string.

Examples:

Sashite::Cell.validate("e4")  # => nil
Sashite::Cell.validate("a0")  # => raises Sashite::Cell::Errors::Argument

Parameters:

  • string (String)

    CELL coordinate string

Returns:

  • (nil)

Raises:



64
65
66
67
# File 'lib/sashite/cell.rb', line 64

def self.validate(string)
  Parser.parse_to_indices(string)
  nil
end