Class: NTable::Structure::AxisInfo
- Inherits:
-
Object
- Object
- NTable::Structure::AxisInfo
- Includes:
- Enumerable
- Defined in:
- lib/ntable/structure.rb
Overview
A data structure that provides information about a particular axis/dimension in a Structure. It provides access to the axis object, as well as the axis’s name (if any) and 0-based index into the list of axes. You should never need to create an AxisInfo yourself, but you can obtain one from Structure#axis.
Instance Attribute Summary collapse
-
#axis_index ⇒ Object
readonly
The 0-based index of this axis in the structure.
-
#axis_name ⇒ Object
readonly
The name of this axis in the structure as a string, or nil for no name.
-
#axis_object ⇒ Object
readonly
The underlying axis implementation.
-
#step ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#_compute_offset(v_) ⇒ Object
:nodoc:.
-
#_dec_index ⇒ Object
:nodoc:.
-
#_set_axis(axis_) ⇒ Object
:nodoc:.
-
#_set_step(step_) ⇒ Object
:nodoc:.
-
#each ⇒ Object
Iterate over the labels, in order.
-
#eql?(obj_) ⇒ Boolean
(also: #==)
Standard equality check.
-
#index(label_) ⇒ Object
Given a label object, return the corresponding 0-based integer index.
-
#initialize(axis_, index_, name_, step_ = nil) ⇒ AxisInfo
constructor
:nodoc:.
-
#label(index_) ⇒ Object
(also: #[])
Given a 0-based integer index, return the corresponding label object.
-
#size ⇒ Object
Return the number of rows along this axis.
Constructor Details
#initialize(axis_, index_, name_, step_ = nil) ⇒ AxisInfo
:nodoc:
70 71 72 73 74 75 |
# File 'lib/ntable/structure.rb', line 70 def initialize(axis_, index_, name_, step_=nil) # :nodoc: @axis_object = axis_ @axis_index = index_ @axis_name = name_ @step = step_ end |
Instance Attribute Details
#axis_index ⇒ Object (readonly)
The 0-based index of this axis in the structure. i.e. the first, most major axis has number 0.
83 84 85 |
# File 'lib/ntable/structure.rb', line 83 def axis_index @axis_index end |
#axis_name ⇒ Object (readonly)
The name of this axis in the structure as a string, or nil for no name.
87 88 89 |
# File 'lib/ntable/structure.rb', line 87 def axis_name @axis_name end |
#axis_object ⇒ Object (readonly)
The underlying axis implementation
79 80 81 |
# File 'lib/ntable/structure.rb', line 79 def axis_object @axis_object end |
#step ⇒ Object (readonly)
:nodoc:
89 90 91 |
# File 'lib/ntable/structure.rb', line 89 def step @step end |
Instance Method Details
#_compute_offset(v_) ⇒ Object
:nodoc:
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ntable/structure.rb', line 154 def _compute_offset(v_) # :nodoc: if v_.is_a?(::NTable::IndexWrapper) index_ = v_.to_i index_ = nil if index_ < 0 || index_ >= @axis_object.size else index_ = @axis_object.index(v_) index_ = v_ if !index_ && v_.is_a?(::Integer) && v_ >= 0 && v_ < @axis_object.size end index_ ? @step * index_ : nil end |
#_dec_index ⇒ Object
:nodoc:
149 150 151 |
# File 'lib/ntable/structure.rb', line 149 def _dec_index # :nodoc: @axis_index -= 1 end |
#_set_axis(axis_) ⇒ Object
:nodoc:
141 142 143 |
# File 'lib/ntable/structure.rb', line 141 def _set_axis(axis_) # :nodoc: @axis_object = axis_ end |
#_set_step(step_) ⇒ Object
:nodoc:
145 146 147 |
# File 'lib/ntable/structure.rb', line 145 def _set_step(step_) # :nodoc: @step = step_ end |
#each ⇒ Object
Iterate over the labels, in order.
120 121 122 123 124 125 126 127 128 |
# File 'lib/ntable/structure.rb', line 120 def each if block_given? @axis_object.size.times do |i_| yield @axis_object.label(i_) end else to_enum end end |
#eql?(obj_) ⇒ Boolean Also known as: ==
Standard equality check
135 136 137 |
# File 'lib/ntable/structure.rb', line 135 def eql?(obj_) obj_.is_a?(AxisInfo) && @axis_object.eql?(obj_.axis_object) && @axis_name.eql?(obj_.axis_name) end |
#index(label_) ⇒ Object
Given a label object, return the corresponding 0-based integer index. Returns nil if the label is not recognized.
95 96 97 |
# File 'lib/ntable/structure.rb', line 95 def index(label_) @axis_object.index(label_) end |
#label(index_) ⇒ Object Also known as: []
Given a 0-based integer index, return the corresponding label object. Returns nil if the index is out of bounds (i.e. is less than 0 or greater than or equal to size.)
104 105 106 |
# File 'lib/ntable/structure.rb', line 104 def label(index_) @axis_object.label(index_) end |
#size ⇒ Object
Return the number of rows along this axis. An empty axis will return 0.
113 114 115 |
# File 'lib/ntable/structure.rb', line 113 def size @axis_object.size end |