Class: Sprint

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sprint.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



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

Returns:

  • (Boolean)


53
54
55
# File 'app/models/sprint.rb', line 53

def completed?
  Date.today > end_date
end

#ends_atObject



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

#nextObject



33
34
35
# File 'app/models/sprint.rb', line 33

def next
  Sprint.find_or_create_by(end_date: end_date + 7)
end

#previousObject



29
30
31
# File 'app/models/sprint.rb', line 29

def previous
  Sprint.find_or_create_by(end_date: end_date - 7)
end

#rangeObject



65
66
67
# File 'app/models/sprint.rb', line 65

def range
  starts_at..ends_at
end

#start_dateObject



37
38
39
# File 'app/models/sprint.rb', line 37

def start_date
  end_date.beginning_of_week
end

#starts_atObject



41
42
43
# File 'app/models/sprint.rb', line 41

def starts_at
  start_date.beginning_of_day
end

#to_rangeObject



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