Class: Calorie::Calendar
- Inherits:
-
Object
- Object
- Calorie::Calendar
- Defined in:
- lib/calorie/calendar.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#weeks ⇒ Object
readonly
Returns the value of attribute weeks.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #current ⇒ Object
- #days_of_the_week ⇒ Object
- #first_day ⇒ Object
-
#initialize(year, month, data = {}) ⇒ Calendar
constructor
A new instance of Calendar.
- #initialize_days ⇒ Object
- #last_day ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(year, month, data = {}) ⇒ Calendar
Returns a new instance of Calendar.
6 7 8 9 10 11 12 |
# File 'lib/calorie/calendar.rb', line 6 def initialize(year, month, data = {}) @data = data @year = year @month = month initialize_days @weeks = WeeksInMonth.new(days).weeks end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/calorie/calendar.rb', line 5 def data @data end |
#days ⇒ Object (readonly)
Returns the value of attribute days.
5 6 7 |
# File 'lib/calorie/calendar.rb', line 5 def days @days end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/calorie/calendar.rb', line 5 def month @month end |
#weeks ⇒ Object (readonly)
Returns the value of attribute weeks.
5 6 7 |
# File 'lib/calorie/calendar.rb', line 5 def weeks @weeks end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/calorie/calendar.rb', line 5 def year @year end |
Instance Method Details
#current ⇒ Object
48 49 50 |
# File 'lib/calorie/calendar.rb', line 48 def current Calorie.label_for(first_day) end |
#days_of_the_week ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/calorie/calendar.rb', line 32 def days_of_the_week unless @days_of_the_week @days_of_the_week ||= (0..6).map do |i| DayOfTheWeek.new(i) end if Calorie.configuration.week_starts_on? :monday @days_of_the_week.push(@days_of_the_week.shift) end end @days_of_the_week end |
#first_day ⇒ Object
14 15 16 17 |
# File 'lib/calorie/calendar.rb', line 14 def first_day @first_day ||= Date.new(year, month, 1) @first_day end |
#initialize_days ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/calorie/calendar.rb', line 24 def initialize_days @days = [] (first_day.mday..last_day.mday).map do |i| date = Date.new(year, month, i) @days << Calorie::Day.new(date, data[i]) end end |
#last_day ⇒ Object
19 20 21 22 |
# File 'lib/calorie/calendar.rb', line 19 def last_day @last_day ||= first_day.next_month.prev_day @last_day end |