Class: MusicBrainz::Model::Rating

Inherits:
Object
  • Object
show all
Defined in:
lib/rbrainz/model/rating.rb

Overview

Represents a rating of an entity.

MusicBrainz allows it’s users to rate artists, labels, releases and tracks. Each user rating will be a Float between 1 and 5 or nil, where nil means no rating. The system will aggregate user ratings to compute the average community rating.

See

wiki.musicbrainz.org/RatingSystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, count = nil) ⇒ Rating

Returns a new instance of Rating.



28
29
30
31
# File 'lib/rbrainz/model/rating.rb', line 28

def initialize(value=nil, count=nil)
  @value = value.nil? ? nil : value.to_f
  @count = count.nil? ? nil : count.to_i
end

Instance Attribute Details

#countObject

The rating count indicating how often entity was rated.



26
27
28
# File 'lib/rbrainz/model/rating.rb', line 26

def count
  @count
end

#valueObject

The rating (an Float between 1 and 5). If :count is greater than 1 this will be the average rating.



23
24
25
# File 'lib/rbrainz/model/rating.rb', line 23

def value
  @value
end

Instance Method Details

#empty?Boolean

Tests if this rating is empty

Returns:

  • (Boolean)


49
50
51
# File 'lib/rbrainz/model/rating.rb', line 49

def empty?
  return value.nil?
end

#to_fObject

Convert this rating into a Float. Will return rating.



44
45
46
# File 'lib/rbrainz/model/rating.rb', line 44

def to_f
  return value.to_f
end

#to_iObject

Convert this rating into an Integer. Will return rating.



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

def to_i
  return value.to_i
end

#to_sObject

Convert this rating into a String. Will return rating.



34
35
36
# File 'lib/rbrainz/model/rating.rb', line 34

def to_s
  return value.to_s
end