Class: Rerout::Models::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/models.rb

Overview

A label attached to a link — ‘{ id:, name:, color: }`. Read-only; the API ignores tag writes for API-key clients.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, color:) ⇒ Tag

Returns a new instance of Tag.



13
14
15
16
17
18
# File 'lib/rerout/models.rb', line 13

def initialize(id:, name:, color:)
  @id = id
  @name = name
  @color = color
  freeze
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



11
12
13
# File 'lib/rerout/models.rb', line 11

def color
  @color
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/rerout/models.rb', line 11

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/rerout/models.rb', line 11

def name
  @name
end

Class Method Details

.from_hash(hash) ⇒ Object



20
21
22
# File 'lib/rerout/models.rb', line 20

def self.from_hash(hash)
  new(id: hash['id'], name: hash['name'], color: hash['color'])
end

Instance Method Details

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



28
29
30
# File 'lib/rerout/models.rb', line 28

def ==(other)
  other.is_a?(Tag) && other.id == id && other.name == name && other.color == color
end

#hashObject



33
34
35
# File 'lib/rerout/models.rb', line 33

def hash
  [self.class, id, name, color].hash
end

#to_hObject



24
25
26
# File 'lib/rerout/models.rb', line 24

def to_h
  { id: id, name: name, color: color }
end