Class: Sprint
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sprint
- Defined in:
- app/models/sprint.rb
Class Method Summary collapse
- .current ⇒ Object
- .end_date_for(date) ⇒ Object
- .find_by_date(date) ⇒ Object
- .find_by_date!(date) ⇒ Object
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #ends_at ⇒ Object
- #lock! ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
- #range ⇒ Object
- #start_date ⇒ Object
- #starts_at ⇒ Object
- #to_range ⇒ Object
- #unlock! ⇒ Object
Class Method Details
.current ⇒ Object
9 10 11 |
# File 'app/models/sprint.rb', line 9 def self.current find_by_date Date.today end |
.end_date_for(date) ⇒ Object
23 24 25 26 27 |
# File 'app/models/sprint.rb', line 23 def self.end_date_for(date) days_until_friday = 5 - date.wday days_until_friday += 7 if days_until_friday < 0 date + days_until_friday end |
.find_by_date(date) ⇒ Object
13 14 15 16 |
# File 'app/models/sprint.rb', line 13 def self.find_by_date(date) date = date.to_date if date.respond_to?(:to_date) find_by_end_date end_date_for(date) end |
.find_by_date!(date) ⇒ Object
18 19 20 21 |
# File 'app/models/sprint.rb', line 18 def self.find_by_date!(date) date = date.to_date if date.respond_to?(:to_date) find_or_create_by(end_date: end_date_for(date)) end |
Instance Method Details
#completed? ⇒ Boolean
53 54 55 |
# File 'app/models/sprint.rb', line 53 def completed? Date.today > end_date end |
#ends_at ⇒ Object
45 46 47 |
# File 'app/models/sprint.rb', line 45 def ends_at end_date.end_of_day end |
#lock! ⇒ Object
57 58 59 |
# File 'app/models/sprint.rb', line 57 def lock! update_column :locked, true end |
#next ⇒ Object
33 34 35 |
# File 'app/models/sprint.rb', line 33 def next Sprint.find_or_create_by(end_date: end_date + 7) end |
#previous ⇒ Object
29 30 31 |
# File 'app/models/sprint.rb', line 29 def previous Sprint.find_or_create_by(end_date: end_date - 7) end |
#range ⇒ Object
65 66 67 |
# File 'app/models/sprint.rb', line 65 def range starts_at..ends_at end |
#start_date ⇒ Object
37 38 39 |
# File 'app/models/sprint.rb', line 37 def start_date end_date.beginning_of_week end |
#starts_at ⇒ Object
41 42 43 |
# File 'app/models/sprint.rb', line 41 def starts_at start_date.beginning_of_day end |
#to_range ⇒ Object
49 50 51 |
# File 'app/models/sprint.rb', line 49 def to_range starts_at..ends_at end |
#unlock! ⇒ Object
61 62 63 |
# File 'app/models/sprint.rb', line 61 def unlock! update_column :locked, false end |