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:



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

#structureObject (readonly)

:nodoc:



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

def structure
  @structure
end

Instance Method Details

#_coordsObject

:nodoc:



255
256
257
# File 'lib/ntable/structure.rb', line 255

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

#_offsetObject

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

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

Returns:

  • (Boolean)


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

#hashObject

Standard hash value



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

def hash
  @structure.hash + @vector.hash
end

#inspectObject 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

#nextObject

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



236
237
238
239
# File 'lib/ntable/structure.rb', line 236

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.



245
246
247
248
# File 'lib/ntable/structure.rb', line 245

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