Class: Sashite::Cell::Coordinate
- Inherits:
-
Object
- Object
- Sashite::Cell::Coordinate
- Defined in:
- lib/sashite/cell/coordinate.rb
Overview
Represents a parsed CELL coordinate with up to 3 dimensions.
A Coordinate holds 0-indexed integer values for each dimension and provides conversion to/from CELL string format.
Instance Attribute Summary collapse
-
#indices ⇒ Array<Integer>
readonly
Returns the coordinate indices as a frozen array.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks equality with another Coordinate.
-
#dimensions ⇒ Integer
Returns the number of dimensions (1, 2, or 3).
-
#hash ⇒ Integer
Returns hash code for use in Hash keys.
-
#initialize(*indices) ⇒ Coordinate
constructor
Creates a Coordinate from 1 to 3 indices.
-
#inspect ⇒ String
Returns a human-readable representation.
-
#to_s ⇒ String
Returns the CELL string representation.
Constructor Details
#initialize(*indices) ⇒ Coordinate
Creates a Coordinate from 1 to 3 indices.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sashite/cell/coordinate.rb', line 40 def initialize(*indices) if indices.empty? raise Errors::Argument, Errors::Argument::Messages::NO_INDICES end if indices.size > Constants::MAX_DIMENSIONS raise Errors::Argument, Errors::Argument::Messages::TOO_MANY_DIMENSIONS end indices.each do |index| unless index.is_a?(::Integer) && index >= 0 && index <= Constants::MAX_INDEX_VALUE raise Errors::Argument, Errors::Argument::Messages::INDEX_OUT_OF_RANGE end end @indices = indices.freeze end |
Instance Attribute Details
#indices ⇒ Array<Integer> (readonly)
Returns the coordinate indices as a frozen array.
30 31 32 |
# File 'lib/sashite/cell/coordinate.rb', line 30 def indices @indices end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks equality with another Coordinate.
85 86 87 |
# File 'lib/sashite/cell/coordinate.rb', line 85 def ==(other) other.is_a?(Coordinate) && @indices == other.indices end |
#dimensions ⇒ Integer
Returns the number of dimensions (1, 2, or 3).
64 65 66 |
# File 'lib/sashite/cell/coordinate.rb', line 64 def dimensions @indices.size end |
#hash ⇒ Integer
Returns hash code for use in Hash keys.
98 99 100 |
# File 'lib/sashite/cell/coordinate.rb', line 98 def hash @indices.hash end |
#inspect ⇒ String
Returns a human-readable representation.
108 109 110 |
# File 'lib/sashite/cell/coordinate.rb', line 108 def inspect "#<#{self.class} #{self}>" end |
#to_s ⇒ String
Returns the CELL string representation.
74 75 76 |
# File 'lib/sashite/cell/coordinate.rb', line 74 def to_s Formatter.indices_to_string(@indices) end |