Class: DataSet::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/tukey/data_set/label.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, id: nil, meta: {}) ⇒ Label

Returns a new instance of Label.



9
10
11
12
13
14
# File 'lib/tukey/data_set/label.rb', line 9

def initialize(name, id: nil, meta: {})
  @name = name
  @id = id || name
  fail ArgumentError, 'DataSet::Label meta must be a Hash' unless meta.is_a?(Hash)
  @meta = OpenStruct.new(meta)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tukey/data_set/label.rb', line 5

def id
  @id
end

#metaObject

Returns the value of attribute meta.



7
8
9
# File 'lib/tukey/data_set/label.rb', line 7

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/tukey/data_set/label.rb', line 6

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object

is used for comparison of two instances directly



17
18
19
# File 'lib/tukey/data_set/label.rb', line 17

def ==(other)
  other.id == id
end

#deep_dupObject



31
32
33
34
35
36
37
# File 'lib/tukey/data_set/label.rb', line 31

def deep_dup
  label = dup
  id = id.dup if id
  name = name.dup if name
  meta = meta.dup if meta
  label
end

#eql?(other) ⇒ Boolean

eql? and hash are both used for comparisons when you call ‘.uniq` on an array of labels.

Returns:

  • (Boolean)


23
24
25
# File 'lib/tukey/data_set/label.rb', line 23

def eql?(other)
  self == other
end

#hashObject



27
28
29
# File 'lib/tukey/data_set/label.rb', line 27

def hash
  id.hash
end