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