Class: NTable::IndexedAxis
- Inherits:
-
Object
- Object
- NTable::IndexedAxis
- Defined in:
- lib/ntable/axis.rb
Overview
An axis in which the rows are numerically identified by a range of consecutive integers.
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #eql?(obj_) ⇒ Boolean (also: #==)
- #from_json_object(json_obj_) ⇒ Object
- #hash ⇒ Object
- #index(label_) ⇒ Object
-
#initialize(size_, start_ = 0) ⇒ IndexedAxis
constructor
Create an IndexedAxis with the given number of rows.
- #inspect ⇒ Object (also: #to_s)
- #label(index_) ⇒ Object
- #to_json_object(json_obj_) ⇒ Object
Constructor Details
#initialize(size_, start_ = 0) ⇒ IndexedAxis
Create an IndexedAxis with the given number of rows. The optional start parameter indicates the number of the first row (default 0).
185 186 187 188 |
# File 'lib/ntable/axis.rb', line 185 def initialize(size_, start_=0) @size = size_ @start = start_ end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
206 207 208 |
# File 'lib/ntable/axis.rb', line 206 def size @size end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
207 208 209 |
# File 'lib/ntable/axis.rb', line 207 def start @start end |
Instance Method Details
#eql?(obj_) ⇒ Boolean Also known as: ==
191 192 193 |
# File 'lib/ntable/axis.rb', line 191 def eql?(obj_) obj_.is_a?(IndexedAxis) && obj_.size.eql?(@size) && obj_.start.eql?(@start) end |
#from_json_object(json_obj_) ⇒ Object
224 225 226 |
# File 'lib/ntable/axis.rb', line 224 def from_json_object(json_obj_) initialize(json_obj_['size'], json_obj_['start'].to_i) end |
#hash ⇒ Object
196 197 198 |
# File 'lib/ntable/axis.rb', line 196 def hash @size.hash ^ @start.hash end |
#index(label_) ⇒ Object
210 211 212 |
# File 'lib/ntable/axis.rb', line 210 def index(label_) label_ >= @start && label_ < @size + @start ? label_ - @start : nil end |
#inspect ⇒ Object Also known as: to_s
200 201 202 |
# File 'lib/ntable/axis.rb', line 200 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} size=#{@size} start=#{@start}>" end |
#label(index_) ⇒ Object
214 215 216 |
# File 'lib/ntable/axis.rb', line 214 def label(index_) index_ >= 0 && index_ < @size ? index_ + @start : nil end |
#to_json_object(json_obj_) ⇒ Object
219 220 221 222 |
# File 'lib/ntable/axis.rb', line 219 def to_json_object(json_obj_) json_obj_['size'] = @size json_obj_['start'] = @start unless @start == 0 end |