class NTable::LabeledAxis

An axis in which the labels are explicitly provided as strings.

Attributes

Public Class Methods

new(*labels_) click to toggle source

Create a LabeledAxis given an array of the label strings. Symbols may also be provided, but will be converted to strings.

# 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

Public Instance Methods

==(obj_) click to toggle source
Alias for: eql?
eql?(obj_) click to toggle source

See NTable::EmptyAxis#eql?

# File lib/ntable/axis.rb, line 135
def eql?(obj_)
  obj_.is_a?(LabeledAxis) && @a.eql?(obj_.instance_variable_get(:@a))
end
Also aliased as: ==
from_json_object(json_obj_) click to toggle source

See NTable::EmptyAxis#from_json_object

# File lib/ntable/axis.rb, line 173
def from_json_object(json_obj_)
  initialize(json_obj_['labels'] || [])
end
hash() click to toggle source

See NTable::EmptyAxis#hash

# File lib/ntable/axis.rb, line 141
def hash
  @a.hash
end
index(label_) click to toggle source

See NTable::EmptyAxis#index

# File lib/ntable/axis.rb, line 157
def index(label_)
  @h[label_.to_s]
end
inspect() click to toggle source

See NTable::EmptyAxis#inspect

# File lib/ntable/axis.rb, line 146
def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} #{@a.inspect}>"
end
Also aliased as: to_s
label(index_) click to toggle source

See NTable::EmptyAxis#label

# File lib/ntable/axis.rb, line 162
def label(index_)
  @a[index_]
end
to_json_object(json_obj_) click to toggle source

See NTable::EmptyAxis#to_json_object

# File lib/ntable/axis.rb, line 168
def to_json_object(json_obj_)
  json_obj_['labels'] = @a
end
to_s() click to toggle source
Alias for: inspect