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: #==)
-
#initialize(structure_, vector_) ⇒ Position
constructor
:nodoc:.
-
#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:
144 145 146 147 148 |
# File 'lib/ntable/structure.rb', line 144 def initialize(structure_, vector_) # :nodoc: @structure = structure_ @vector = vector_ @offset = @coords = nil end |
Instance Attribute Details
#structure ⇒ Object (readonly)
:nodoc:
156 157 158 |
# File 'lib/ntable/structure.rb', line 156 def structure @structure end |
Instance Method Details
#_coords ⇒ Object
:nodoc:
199 200 201 |
# File 'lib/ntable/structure.rb', line 199 def _coords # :nodoc: @coords ||= @structure._compute_coords_for_vector(@vector) end |
#_offset ⇒ Object
:nodoc:
195 196 197 |
# File 'lib/ntable/structure.rb', line 195 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.
162 163 164 165 |
# File 'lib/ntable/structure.rb', line 162 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.
172 173 174 |
# File 'lib/ntable/structure.rb', line 172 def coord_array _coords.dup end |
#eql?(obj_) ⇒ Boolean Also known as: ==
151 152 153 |
# File 'lib/ntable/structure.rb', line 151 def eql?(obj_) obj_.is_a?(Position) && obj_.structure.eql?(@structure) && obj_._offset.eql?(self._offset) end |