Class: Fixversion::Base
- Inherits:
-
Object
- Object
- Fixversion::Base
- Defined in:
- lib/fixversion/base.rb
Constant Summary collapse
- CUTOFFS =
{ 'wednesday': { cutoff: '11:00 am MST', release: 'thursday' }, 'friday': { cutoff: '11:00 am MST', release: 'tuesday' } }.with_indifferent_access
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
Instance Method Summary collapse
- #before_cutoff_time? ⇒ Boolean
- #cutoff_day? ⇒ Boolean
- #cutoff_days ⇒ Object
- #cutoff_index ⇒ Object
- #cutoff_time ⇒ Object
- #cutoff_time_string ⇒ Object
- #day_of_week ⇒ Object
- #days_of_week_names ⇒ Object
- #dow_after_cutoff_time ⇒ Object
- #dow_before_cutoff_time ⇒ Object
- #fix_version ⇒ Object
-
#initialize(date) ⇒ Base
constructor
A new instance of Base.
- #next_cutoff ⇒ Object
- #next_cutoff_dow ⇒ Object
- #next_release_day ⇒ Object
Constructor Details
#initialize(date) ⇒ Base
Returns a new instance of Base.
19 20 21 |
# File 'lib/fixversion/base.rb', line 19 def initialize(date) @date = date end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
17 18 19 |
# File 'lib/fixversion/base.rb', line 17 def date @date end |
Instance Method Details
#before_cutoff_time? ⇒ Boolean
56 57 58 |
# File 'lib/fixversion/base.rb', line 56 def before_cutoff_time? date < cutoff_time end |
#cutoff_day? ⇒ Boolean
31 32 33 |
# File 'lib/fixversion/base.rb', line 31 def cutoff_day? CUTOFFS.keys.include?(day_of_week) end |
#cutoff_days ⇒ Object
23 24 25 |
# File 'lib/fixversion/base.rb', line 23 def cutoff_days CUTOFFS.keys end |
#cutoff_index ⇒ Object
39 40 41 |
# File 'lib/fixversion/base.rb', line 39 def cutoff_index CUTOFFS.keys.index(cutoff) end |
#cutoff_time ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/fixversion/base.rb', line 47 def cutoff_time base = Time.parse(cutoff_time_string).to_datetime updated = base.change( day: date.day, month: date.month, year: date.year ) end |
#cutoff_time_string ⇒ Object
43 44 45 |
# File 'lib/fixversion/base.rb', line 43 def cutoff_time_string '11:00 am MST' end |
#day_of_week ⇒ Object
27 28 29 |
# File 'lib/fixversion/base.rb', line 27 def day_of_week date.strftime("%A").downcase end |
#days_of_week_names ⇒ Object
60 |
# File 'lib/fixversion/base.rb', line 60 def days_of_week_names = Date::DAYNAMES.map(&:downcase) |
#dow_after_cutoff_time ⇒ Object
74 75 76 77 78 |
# File 'lib/fixversion/base.rb', line 74 def dow_after_cutoff_time dow_index = days_of_week_names.index(day_of_week) rotated = days_of_week_names.rotate(dow_index + 1) rotated.detect { |dow| CUTOFFS.keys.include?(dow) } end |
#dow_before_cutoff_time ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/fixversion/base.rb', line 66 def dow_before_cutoff_time return day_of_week if cutoff_day? dow_index = days_of_week_names.index(day_of_week) rotated = days_of_week_names.rotate(dow_index) rotated.detect { |dow| CUTOFFS.keys.include?(dow) } end |
#fix_version ⇒ Object
35 36 37 |
# File 'lib/fixversion/base.rb', line 35 def fix_version next_release_day.strftime('%Y.%m.%d') end |
#next_cutoff ⇒ Object
62 63 64 |
# File 'lib/fixversion/base.rb', line 62 def next_cutoff CUTOFFS[next_cutoff_dow] end |
#next_cutoff_dow ⇒ Object
80 81 82 83 84 |
# File 'lib/fixversion/base.rb', line 80 def next_cutoff_dow return dow_before_cutoff_time if before_cutoff_time? dow_after_cutoff_time end |
#next_release_day ⇒ Object
86 87 88 89 |
# File 'lib/fixversion/base.rb', line 86 def next_release_day next_release_dow = next_cutoff['release'] date.next_occurring(next_release_dow.to_sym) end |