Module: Yt::Associations::Views
- Defined in:
- lib/yt/associations/views.rb
Overview
Provides the ‘has_many :views` method to YouTube resources, which allows to invoke view-related methods, such as .views. YouTube resources with views are: channels.
Instance Method Summary collapse
-
#views(options = {}) ⇒ Hash
Return the view count for a range of days.
-
#views_on(date) ⇒ Integer or Nil
Return the view count for one specific day.
Instance Method Details
#views(options = {}) ⇒ Hash
31 32 33 34 35 36 37 38 39 |
# File 'lib/yt/associations/views.rb', line 31 def views( = {}) from = [:since] || [:from] || 5.days.ago to = [:until] || [:to] || 1.day.ago range = Range.new *[from, to].map(&:to_date) Hash[*range.flat_map do |date| [date, (@views ||= {})[date] ||= range_views(range)[date]] end] end |
#views_on(date) ⇒ Integer or Nil
Return the view count for one specific day.
the estimated views for. If String, must be Date-parseable.
15 16 17 |
# File 'lib/yt/associations/views.rb', line 15 def views_on(date) views(from: date, to: date).values.first end |