Class: SimpleCalendar::WeekCalendar

Inherits:
Calendar
  • Object
show all
Defined in:
lib/simple_calendar/week_calendar.rb

Constant Summary

Constants inherited from Calendar

Calendar::PARAM_KEY_BLACKLIST

Instance Attribute Summary

Attributes inherited from Calendar

#options, #view_context

Instance Method Summary collapse

Methods inherited from Calendar

#additional_days, #attribute, #end_attribute, #end_date, #group_events_by_date, #initialize, #locals, #partial_name, #render_in, #sorted_events, #sorted_events_for, #start_date, #start_date_param, #td_classes_for, #tr_classes_for, #url_for_next_view, #url_for_today_view

Constructor Details

This class inherits a constructor from SimpleCalendar::Calendar

Instance Method Details

#date_rangeObject



16
17
18
19
20
21
# File 'lib/simple_calendar/week_calendar.rb', line 16

def date_range
  starting = start_date.beginning_of_week
  ending = (starting + (number_of_weeks - 1).weeks).end_of_week

  (starting..ending).to_a
end

#end_weekObject



12
13
14
# File 'lib/simple_calendar/week_calendar.rb', line 12

def end_week
  week_number + number_of_weeks - 1
end

#number_of_weeksObject



8
9
10
# File 'lib/simple_calendar/week_calendar.rb', line 8

def number_of_weeks
  options.fetch(:number_of_weeks, 1)
end

#url_for_previous_viewObject



23
24
25
# File 'lib/simple_calendar/week_calendar.rb', line 23

def url_for_previous_view
  view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
end

#week_numberObject



3
4
5
6
# File 'lib/simple_calendar/week_calendar.rb', line 3

def week_number
  format = (Date.beginning_of_week == :sunday) ? "%U" : "%V"
  start_date.beginning_of_week.strftime(format).to_i
end