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:.
-
#inspect ⇒ Object
(also: #to_s)
Basic output.
-
#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.
91 92 93 |
# File 'lib/ntable/structure.rb', line 91 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.
95 96 97 |
# File 'lib/ntable/structure.rb', line 95 def axis_name @axis_name end |
#axis_object ⇒ Object (readonly)
The underlying axis implementation
87 88 89 |
# File 'lib/ntable/structure.rb', line 87 def axis_object @axis_object end |
#step ⇒ Object (readonly)
:nodoc:
97 98 99 |
# File 'lib/ntable/structure.rb', line 97 def step @step end |
Instance Method Details
#_compute_offset(v_) ⇒ Object
:nodoc:
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ntable/structure.rb', line 162 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:
157 158 159 |
# File 'lib/ntable/structure.rb', line 157 def _dec_index # :nodoc: @axis_index -= 1 end |
#_set_axis(axis_) ⇒ Object
:nodoc:
149 150 151 |
# File 'lib/ntable/structure.rb', line 149 def _set_axis(axis_) # :nodoc: @axis_object = axis_ end |
#_set_step(step_) ⇒ Object
:nodoc:
153 154 155 |
# File 'lib/ntable/structure.rb', line 153 def _set_step(step_) # :nodoc: @step = step_ end |
#each ⇒ Object
Iterate over the labels, in order.
128 129 130 131 132 133 134 135 136 |
# File 'lib/ntable/structure.rb', line 128 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
143 144 145 |
# File 'lib/ntable/structure.rb', line 143 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.
103 104 105 |
# File 'lib/ntable/structure.rb', line 103 def index(label_) @axis_object.index(label_) end |
#inspect ⇒ Object Also known as: to_s
Basic output.
80 81 82 |
# File 'lib/ntable/structure.rb', line 80 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} #{@axis_name}:#{@axis_object.class.name.sub('NTable::', '')}>" 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.)
112 113 114 |
# File 'lib/ntable/structure.rb', line 112 def label(index_) @axis_object.label(index_) end |
#size ⇒ Object
Return the number of rows along this axis. An empty axis will return 0.
121 122 123 |
# File 'lib/ntable/structure.rb', line 121 def size @axis_object.size end |