Class: ConvenientService::Support::UniqueValue

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/support/unique_value.rb

Direct Known Subclasses

NotPassed, Undefined

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = default_label) ⇒ void

Parameters:

  • label (String) (defaults to: default_label)


21
22
23
# File 'lib/convenient_service/support/unique_value.rb', line 21

def initialize(label = default_label)
  @label = label
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



15
16
17
# File 'lib/convenient_service/support/unique_value.rb', line 15

def label
  @label
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


33
34
35
36
37
# File 'lib/convenient_service/support/unique_value.rb', line 33

def ==(other)
  return unless other.instance_of?(self.class)

  equal?(other)
end

#===(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


43
44
45
# File 'lib/convenient_service/support/unique_value.rb', line 43

def ===(other)
  self == other
end

#eql?(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


57
58
59
60
61
# File 'lib/convenient_service/support/unique_value.rb', line 57

def eql?(other)
  return unless other.instance_of?(self.class)

  object_id == other.object_id
end

#hashInteger

Returns:

  • (Integer)


70
71
72
# File 'lib/convenient_service/support/unique_value.rb', line 70

def hash
  [self.class, label].hash
end

#inspectString

Returns:

  • (String)


77
78
79
80
81
82
# File 'lib/convenient_service/support/unique_value.rb', line 77

def inspect
  return default_label if label.nil?
  return default_label if label.empty?

  label
end