Class: HTMLCalendar::Calendar

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, month, options = {}) ⇒ Calendar

Returns a new instance of Calendar.



5
6
7
8
9
# File 'lib/html_calendar/calendar.rb', line 5

def initialize(template, month, options = {})
  @template = template
  @month = Month.new(month)
  @options = options
end

Instance Attribute Details

#monthObject (readonly)

Returns the value of attribute month.



3
4
5
# File 'lib/html_calendar/calendar.rb', line 3

def month
  @month
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/html_calendar/calendar.rb', line 3

def options
  @options
end

#templateObject (readonly)

Returns the value of attribute template.



3
4
5
# File 'lib/html_calendar/calendar.rb', line 3

def template
  @template
end

Instance Method Details

#in_month?(date) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/html_calendar/calendar.rb', line 35

def in_month?(date)
  date_range.include? date
end

#prefixObject



39
40
41
# File 'lib/html_calendar/calendar.rb', line 39

def prefix
  self.class.name.underscore
end

#render_date(date) ⇒ Object



30
31
32
33
# File 'lib/html_calendar/calendar.rb', line 30

def render_date(date)
  partial_name = in_month?(date) ? 'day' : 'other_month_day'
  render partial_name, date: date, presenter: date_presenter_for(date)
end

#render_headerObject



26
27
28
# File 'lib/html_calendar/calendar.rb', line 26

def render_header
  render 'header', month: month
end

#renderable_date_rangeObject



18
19
20
# File 'lib/html_calendar/calendar.rb', line 18

def renderable_date_range
  beginning_of_month.at_beginning_of_week(:sunday)..end_of_month.at_end_of_week(:sunday)
end

#renderable_date_range_in_weeksObject



22
23
24
# File 'lib/html_calendar/calendar.rb', line 22

def renderable_date_range_in_weeks
  renderable_date_range.to_a.in_groups_of(7)
end

#to_sObject



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

def to_s
  render 'calendar', calendar: self
end