Class: Week

Inherits:
Object
  • Object
show all
Defined in:
lib/sane_week.rb

Overview

a week that always starts on a monday

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = Date.today) ⇒ Week

Returns a new instance of Week.



8
9
10
11
# File 'lib/sane_week.rb', line 8

def initialize(date = Date.today)
  @start_date = find_monday(date)
  process_days
end

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



4
5
6
# File 'lib/sane_week.rb', line 4

def end_date
  @end_date
end

#fridayObject

Returns the value of attribute friday.



4
5
6
# File 'lib/sane_week.rb', line 4

def friday
  @friday
end

#mondayObject

Returns the value of attribute monday.



4
5
6
# File 'lib/sane_week.rb', line 4

def monday
  @monday
end

#saturdayObject

Returns the value of attribute saturday.



4
5
6
# File 'lib/sane_week.rb', line 4

def saturday
  @saturday
end

#start_dateObject

Returns the value of attribute start_date.



4
5
6
# File 'lib/sane_week.rb', line 4

def start_date
  @start_date
end

#sundayObject

Returns the value of attribute sunday.



4
5
6
# File 'lib/sane_week.rb', line 4

def sunday
  @sunday
end

#thursdayObject

Returns the value of attribute thursday.



4
5
6
# File 'lib/sane_week.rb', line 4

def thursday
  @thursday
end

#tuesdayObject

Returns the value of attribute tuesday.



4
5
6
# File 'lib/sane_week.rb', line 4

def tuesday
  @tuesday
end

#wednesdayObject

Returns the value of attribute wednesday.



4
5
6
# File 'lib/sane_week.rb', line 4

def wednesday
  @wednesday
end

Instance Method Details

#find_monday(date) ⇒ Object

gets the nearest past monday relative to the date given



14
15
16
# File 'lib/sane_week.rb', line 14

def find_monday date
  date.monday? ? date : find_monday(date - 1)
end