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:



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

def initialize(structure_, vector_)  # :nodoc:
  @structure = structure_
  @vector = vector_
  @offset = @coords = nil
end

Instance Attribute Details

#structureObject (readonly)

:nodoc:



168
169
170
# File 'lib/ntable/structure.rb', line 168

def structure
  @structure
end

Instance Method Details

#_coordsObject

:nodoc:



211
212
213
# File 'lib/ntable/structure.rb', line 211

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

#_offsetObject

:nodoc:



207
208
209
# File 'lib/ntable/structure.rb', line 207

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.



174
175
176
177
# File 'lib/ntable/structure.rb', line 174

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.



184
185
186
# File 'lib/ntable/structure.rb', line 184

def coord_array
  _coords.dup
end

#eql?(obj_) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


163
164
165
# File 'lib/ntable/structure.rb', line 163

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.



192
193
194
195
# File 'lib/ntable/structure.rb', line 192

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.



201
202
203
204
# File 'lib/ntable/structure.rb', line 201

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