Class: MusicBrainz::Model::ScoredCollection::Entry

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rbrainz/model/scored_collection.rb

Overview

An entry in a ScoredCollection wrapping an entity and a corresponding search result score.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, score = nil) ⇒ Entry



38
39
40
41
# File 'lib/rbrainz/model/scored_collection.rb', line 38

def initialize(entity, score=nil)
  @entity = entity
  @score  = score
end

Instance Attribute Details

#entityObject

Returns the value of attribute entity.



36
37
38
# File 'lib/rbrainz/model/scored_collection.rb', line 36

def entity
  @entity
end

#scoreObject

Returns the value of attribute score.



36
37
38
# File 'lib/rbrainz/model/scored_collection.rb', line 36

def score
  @score
end

Instance Method Details

#<=>(other) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rbrainz/model/scored_collection.rb', line 43

def <=>(other)
  if self.score.nil? && other.score.nil?
    return self.entity <=> other.entity
  end
  return -1 if self.score.nil?
  return 1 if other.score.nil?
  
  return self.score <=> other.score
end