Module: ScraperUtils::CycleUtils
- Defined in:
- lib/scraper_utils/cycle_utils.rb
Overview
Provides utilities for cycling through a range of options day by day
Class Method Summary collapse
-
.pick(values, date: nil) ⇒ Object
Returns one value per day, cycling through all possible values in order Can override using CYCLE_POSITION ENV variable.
-
.position(cycle, date: nil) ⇒ Integer
Returns position in cycle from zero onwards Can override using CYCLE_POSITION ENV variable.
Class Method Details
.pick(values, date: nil) ⇒ Object
Returns one value per day, cycling through all possible values in order Can override using CYCLE_POSITION ENV variable
21 22 23 24 |
# File 'lib/scraper_utils/cycle_utils.rb', line 21 def self.pick(values, date: nil) values = values.to_a values[position(values.size, date: date)] end |
.position(cycle, date: nil) ⇒ Integer
Returns position in cycle from zero onwards Can override using CYCLE_POSITION ENV variable
11 12 13 14 |
# File 'lib/scraper_utils/cycle_utils.rb', line 11 def self.position(cycle, date: nil) day = ENV.fetch('CYCLE_POSITION', (date || Date.today).jd).to_i day % cycle end |