Class: MusicBrainz::Model::Rating
- Inherits:
-
Object
- Object
- MusicBrainz::Model::Rating
- 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.
Instance Attribute Summary collapse
-
#count ⇒ Object
The rating count indicating how often entity was rated.
-
#value ⇒ Object
The rating (an Float between 1 and 5).
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Tests if this rating is empty.
-
#initialize(value = nil, count = nil) ⇒ Rating
constructor
A new instance of Rating.
-
#to_f ⇒ Object
Convert this rating into a Float.
-
#to_i ⇒ Object
Convert this rating into an Integer.
-
#to_s ⇒ Object
Convert this rating into a String.
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
#count ⇒ Object
The rating count indicating how often entity was rated.
26 27 28 |
# File 'lib/rbrainz/model/rating.rb', line 26 def count @count end |
#value ⇒ Object
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
49 50 51 |
# File 'lib/rbrainz/model/rating.rb', line 49 def empty? return value.nil? end |
#to_f ⇒ Object
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_i ⇒ Object
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_s ⇒ Object
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 |