Class: NTable::LabeledAxis
- Inherits:
-
Object
- Object
- NTable::LabeledAxis
- Defined in:
- lib/ntable/axis.rb
Overview
An axis in which the labels are explicitly provided as strings.
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #==(obj_) ⇒ Object
- #eql?(obj_) ⇒ Boolean
- #from_json_object(json_obj_) ⇒ Object
- #hash ⇒ Object
- #index(label_) ⇒ Object
-
#initialize(*labels_) ⇒ LabeledAxis
constructor
Create a LabeledAxis given an array of the label strings.
- #inspect ⇒ Object (also: #to_s)
- #label(index_) ⇒ Object
- #to_json_object(json_obj_) ⇒ Object
Constructor Details
#initialize(*labels_) ⇒ LabeledAxis
Create a LabeledAxis given an array of the label strings. Symbols may also be provided, but will be converted to strings.
125 126 127 128 129 130 131 |
# File 'lib/ntable/axis.rb', line 125 def initialize(*labels_) labels_ = labels_.flatten @a = labels_.map{ |label_| label_.to_s } @h = {} @a.each_with_index{ |n_, i_| @h[n_] = i_ } @size = labels_.size end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
152 153 154 |
# File 'lib/ntable/axis.rb', line 152 def size @size end |
Instance Method Details
#==(obj_) ⇒ Object
138 139 140 |
# File 'lib/ntable/axis.rb', line 138 def ==(obj_) obj_.is_a?(LabeledAxis) && @a == obj_.instance_variable_get(:@a) end |
#eql?(obj_) ⇒ Boolean
134 135 136 |
# File 'lib/ntable/axis.rb', line 134 def eql?(obj_) obj_.is_a?(LabeledAxis) && @a.eql?(obj_.instance_variable_get(:@a)) end |
#from_json_object(json_obj_) ⇒ Object
168 169 170 |
# File 'lib/ntable/axis.rb', line 168 def from_json_object(json_obj_) initialize(json_obj_['labels'] || []) end |
#hash ⇒ Object
142 143 144 |
# File 'lib/ntable/axis.rb', line 142 def hash @a.hash end |
#index(label_) ⇒ Object
155 156 157 |
# File 'lib/ntable/axis.rb', line 155 def index(label_) @h[label_.to_s] end |
#inspect ⇒ Object Also known as: to_s
146 147 148 |
# File 'lib/ntable/axis.rb', line 146 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} #{@a.inspect}>" end |
#label(index_) ⇒ Object
159 160 161 |
# File 'lib/ntable/axis.rb', line 159 def label(index_) @a[index_] end |
#to_json_object(json_obj_) ⇒ Object
164 165 166 |
# File 'lib/ntable/axis.rb', line 164 def to_json_object(json_obj_) json_obj_['labels'] = @a end |