Class: DateRangeRollout::Rollout
- Inherits:
-
Object
- Object
- DateRangeRollout::Rollout
- Defined in:
- lib/date_range_rollout/rollout.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(start_duration, start_date, end_duration, end_date) ⇒ Rollout
constructor
A new instance of Rollout.
Constructor Details
#initialize(start_duration, start_date, end_duration, end_date) ⇒ Rollout
Returns a new instance of Rollout.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/date_range_rollout/rollout.rb', line 7 def initialize(start_duration, start_date, end_duration, end_date) if start_date > end_date raise DateRangeError, "Start date should be before end date" end @start_duration = start_duration @start_date = start_date @end_duration = end_duration @end_date = end_date end |
Instance Method Details
#get ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/date_range_rollout/rollout.rb', line 18 def get now = Time.now if now <= @start_date return @start_duration.to_f end if now >= @end_date return @end_duration.to_f end offset = now.to_f - @start_date.to_f pct = offset / (@end_date.to_f - @start_date.to_f) pct * (@end_duration - @start_duration) + @start_duration end |