Class: Rerout::Models::TagSummary

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

Overview

A tag with the number of live (non-deleted) links it is attached to —‘{ id:, name:, color:, link_count: }`. Returned by `tags.list`; the create/update responses use the plain Tag (no `link_count`).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, color:, link_count:) ⇒ TagSummary

Returns a new instance of TagSummary.



44
45
46
47
48
49
50
# File 'lib/rerout/models.rb', line 44

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

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



42
43
44
# File 'lib/rerout/models.rb', line 42

def color
  @color
end

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'lib/rerout/models.rb', line 42

def id
  @id
end

Returns the value of attribute link_count.



42
43
44
# File 'lib/rerout/models.rb', line 42

def link_count
  @link_count
end

#nameObject (readonly)

Returns the value of attribute name.



42
43
44
# File 'lib/rerout/models.rb', line 42

def name
  @name
end

Class Method Details

.from_hash(hash) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/rerout/models.rb', line 52

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

Instance Method Details

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



65
66
67
# File 'lib/rerout/models.rb', line 65

def ==(other)
  other.is_a?(TagSummary) && other.to_h == to_h
end

#hashObject



70
71
72
# File 'lib/rerout/models.rb', line 70

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

#to_hObject



61
62
63
# File 'lib/rerout/models.rb', line 61

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