Class: NTable::Structure::Position

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#structureObject (readonly)

:nodoc:



156
157
158
# File 'lib/ntable/structure.rb', line 156

def structure
  @structure
end

Instance Method Details

#_coordsObject

:nodoc:



199
200
201
# File 'lib/ntable/structure.rb', line 199

def _coords  # :nodoc:
  @coords ||= @structure._compute_coords_for_vector(@vector)
end

#_offsetObject

: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_arrayObject

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: ==

Returns:

  • (Boolean)


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

#nextObject

Returns the Position of the “next” cell in the table, or nil if this is the last cell.



180
181
182
183
# File 'lib/ntable/structure.rb', line 180

def next
  v_ = @vector.dup
  @structure._inc_vector(v_) ? nil : Position.new(@structure, v_)
end

#prevObject

Returns the Position of the “previous” cell in the table, or nil if this is the first cell.



189
190
191
192
# File 'lib/ntable/structure.rb', line 189

def prev
  v_ = @vector.dup
  @structure._dec_vector(v_) ? nil : Position.new(@structure, v_)
end