Class: NTable::ObjectAxis

Inherits:
Object
  • Object
show all
Defined in:
lib/ntable/axis.rb

Overview

An axis in which the labels are arbitrary objects. This axis cannot be serialized.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(labels_) ⇒ ObjectAxis

Create a ObjectAxis given an array of the label objects.



255
256
257
258
259
260
# File 'lib/ntable/axis.rb', line 255

def initialize(labels_)
  @a = labels_.dup
  @h = {}
  @a.each_with_index{ |n_, i_| @h[n_] = i_ }
  @size = labels_.size
end

Instance Attribute Details

#sizeObject (readonly)

See EmptyAxis#size



286
287
288
# File 'lib/ntable/axis.rb', line 286

def size
  @size
end

Instance Method Details

#==(obj_) ⇒ Object

See EmptyAxis#==



269
270
271
# File 'lib/ntable/axis.rb', line 269

def ==(obj_)
  obj_.is_a?(ObjectAxis) && @a == obj_.instance_variable_get(:@a)
end

#eql?(obj_) ⇒ Boolean

See EmptyAxis#eql?

Returns:

  • (Boolean)


264
265
266
# File 'lib/ntable/axis.rb', line 264

def eql?(obj_)
  obj_.is_a?(ObjectAxis) && @a.eql?(obj_.instance_variable_get(:@a))
end

#from_json_object(json_obj_) ⇒ Object

See EmptyAxis#from_json_object



306
307
308
# File 'lib/ntable/axis.rb', line 306

def from_json_object(json_obj_)
  raise "Unable to JSON serialize an ObjectAxis"
end

#hashObject

See EmptyAxis#hash



274
275
276
# File 'lib/ntable/axis.rb', line 274

def hash
  @a.hash
end

#index(label_) ⇒ Object

See EmptyAxis#index



290
291
292
# File 'lib/ntable/axis.rb', line 290

def index(label_)
  @h[label_]
end

#inspectObject Also known as: to_s

See EmptyAxis#inspect



279
280
281
# File 'lib/ntable/axis.rb', line 279

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} #{@a.inspect}>"
end

#label(index_) ⇒ Object

See EmptyAxis#label



295
296
297
# File 'lib/ntable/axis.rb', line 295

def label(index_)
  @a[index_]
end

#to_json_object(json_obj_) ⇒ Object

See EmptyAxis#to_json_object



301
302
303
# File 'lib/ntable/axis.rb', line 301

def to_json_object(json_obj_)
  raise "Unable to JSON serialize an ObjectAxis"
end