Module: Yt::Associations::Ratings

Defined in:
lib/yt/associations/ratings.rb

Overview

Provides the ‘has_one :rating` method to YouTube resources, which allows to invoke rating-related methods, such as .like. YouTube resources with rating are: videos.

Instance Method Summary collapse

Instance Method Details

#dislikeObject



22
23
24
25
# File 'lib/yt/associations/ratings.rb', line 22

def dislike
  rating.update :dislike
  !liked?
end

#likeObject



17
18
19
20
# File 'lib/yt/associations/ratings.rb', line 17

def like
  rating.update :like
  liked?
end

#liked?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/yt/associations/ratings.rb', line 13

def liked?
  rating.rating == :like
end

#ratingObject



9
10
11
# File 'lib/yt/associations/ratings.rb', line 9

def rating
  @rating ||= ratings.first
end

#unlikeObject



27
28
29
30
# File 'lib/yt/associations/ratings.rb', line 27

def unlike
  rating.update :none
  !liked?
end