Class: NTable::Structure::Position
- Inherits:
-
Object
- Object
- NTable::Structure::Position
- Defined in:
- lib/ntable/structure.rb
Overview
A coordinate into a table. This object is often provided during iteration to indicate where you are in the iteration. You should not need to create a Position object yourself.
Instance Attribute Summary collapse
-
#structure ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#_coords ⇒ Object
:nodoc:.
-
#_offset ⇒ Object
:nodoc:.
-
#coord(axis_) ⇒ Object
(also: #[])
Returns the label of the coordinate along the given axis.
-
#coord_array ⇒ Object
Returns an array of all coordinate labels along the axes in order.
-
#eql?(obj_) ⇒ Boolean
(also: #==)
Standard equality check.
-
#hash ⇒ Object
Standard hash value.
-
#initialize(structure_, vector_) ⇒ Position
constructor
:nodoc:.
-
#inspect ⇒ Object
(also: #to_s)
Basic output.
-
#next ⇒ Object
Returns the Position of the “next” cell in the table, or nil if this is the last cell.
-
#prev ⇒ Object
Returns the Position of the “previous” cell in the table, or nil if this is the first cell.
Constructor Details
#initialize(structure_, vector_) ⇒ Position
:nodoc:
182 183 184 185 186 |
# File 'lib/ntable/structure.rb', line 182 def initialize(structure_, vector_) # :nodoc: @structure = structure_ @vector = vector_ @offset = @coords = nil end |
Instance Attribute Details
#structure ⇒ Object (readonly)
:nodoc:
212 213 214 |
# File 'lib/ntable/structure.rb', line 212 def structure @structure end |
Instance Method Details
#_coords ⇒ Object
:nodoc:
255 256 257 |
# File 'lib/ntable/structure.rb', line 255 def _coords # :nodoc: @coords ||= @structure._compute_coords_for_vector(@vector) end |
#_offset ⇒ Object
:nodoc:
251 252 253 |
# File 'lib/ntable/structure.rb', line 251 def _offset # :nodoc: @offset ||= @structure._compute_offset_for_vector(@vector) end |
#coord(axis_) ⇒ Object Also known as: []
Returns the label of the coordinate along the given axis. The axis may be provided by name or index.
218 219 220 221 |
# File 'lib/ntable/structure.rb', line 218 def coord(axis_) ainfo_ = @structure.axis(axis_) ainfo_ ? _coords[ainfo_.axis_index] : nil end |
#coord_array ⇒ Object
Returns an array of all coordinate labels along the axes in order.
228 229 230 |
# File 'lib/ntable/structure.rb', line 228 def coord_array _coords.dup end |
#eql?(obj_) ⇒ Boolean Also known as: ==
Standard equality check
199 200 201 |
# File 'lib/ntable/structure.rb', line 199 def eql?(obj_) obj_.is_a?(Position) && obj_.structure.eql?(@structure) && obj_._offset.eql?(self._offset) end |
#hash ⇒ Object
Standard hash value
207 208 209 |
# File 'lib/ntable/structure.rb', line 207 def hash @structure.hash + @vector.hash end |
#inspect ⇒ Object Also known as: to_s
Basic output.
191 192 193 |
# File 'lib/ntable/structure.rb', line 191 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} #{coord_array.inspect}>" end |