Class: Primitive::Entity

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
lib/primitive/entity.rb

Overview

Base class for uniquely identifiable classes. Subclasses are simply based on a string-based ID and comparison/sorting/equality will be done in a case-insensitive manner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = '') ⇒ Entity

Returns a new instance of Entity.



15
16
17
# File 'lib/primitive/entity.rb', line 15

def initialize(id = '')
  @id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/primitive/entity.rb', line 12

def id
  @id
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
# File 'lib/primitive/entity.rb', line 20

def <=>(other)
  comparable_id <=> other.comparable_id
end

#==(other) ⇒ Object Also known as: eql?



25
26
27
# File 'lib/primitive/entity.rb', line 25

def ==(other)
  comparable_id == other.comparable_id
end

#comparable_idObject



41
42
43
# File 'lib/primitive/entity.rb', line 41

def comparable_id
  id.upcase
end

#hashObject



31
32
33
# File 'lib/primitive/entity.rb', line 31

def hash
  comparable_id.hash
end

#to_sObject



36
37
38
# File 'lib/primitive/entity.rb', line 36

def to_s
  id
end