Class: EventCalendarPage

Inherits:
Page
  • Object
show all
Includes:
WillPaginate::ViewHelpers
Defined in:
app/models/event_calendar_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#calendar_categoryObject

Returns the value of attribute calendar_category.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_category
  @calendar_category
end

#calendar_filtersObject

Returns the value of attribute calendar_filters.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_filters
  @calendar_filters
end

#calendar_monthObject

Returns the value of attribute calendar_month.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_month
  @calendar_month
end

#calendar_pageObject

Returns the value of attribute calendar_page.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_page
  @calendar_page
end

#calendar_parametersObject

Returns the value of attribute calendar_parameters.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_parameters
  @calendar_parameters
end

#calendar_periodObject

Returns the value of attribute calendar_period.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_period
  @calendar_period
end

#calendar_slugObject

Returns the value of attribute calendar_slug.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_slug
  @calendar_slug
end

#calendar_yearObject

Returns the value of attribute calendar_year.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def calendar_year
  @calendar_year
end

#filtersObject

Returns the value of attribute filters.



6
7
8
# File 'app/models/event_calendar_page.rb', line 6

def filters
  @filters
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/event_calendar_page.rb', line 10

def cache?
  true
end

#calendar_setObject



59
60
61
62
63
# File 'app/models/event_calendar_page.rb', line 59

def calendar_set
  if calendar_category and calendar_slug 
    calendars.in_category(calendar_category).with_slugs(calendar_slug)
  end
end

#day_namesObject



89
90
91
92
93
94
95
# File 'app/models/event_calendar_page.rb', line 89

def day_names
  unless @day_names
    @day_names = (I18n.t 'date.day_names').dup
    @day_names.push(@day_names.shift) # Class::Date and ActiveSupport::CoreExtensions::Time::Calculations have different ideas of when is the start of the week. we've gone for the rails standard.
  end
  @day_names
end

#find_by_path(path, live = true, clean = true) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/models/event_calendar_page.rb', line 14

def find_by_path(path, live = true, clean = true)
  path = clean_path(path) if clean
  my_path = self.path_without_parts
  if path =~ /^#{Regexp.quote(my_path)}(.*)/
    read_parameters($1)
    self
  else
    nil
  end
end

#month_namesObject



85
86
87
# File 'app/models/event_calendar_page.rb', line 85

def month_names
  @month_names ||= (I18n.t 'date.month_names').dup
end

#path_partsObject



65
66
67
68
69
70
71
72
73
74
# File 'app/models/event_calendar_page.rb', line 65

def path_parts
  {
    :path => path_without_parts,
    :day => @calendar_day,
    :month => @calendar_month,
    :year => @calendar_year,
    :category => @calendar_category,
    :slug => @calendar_slug
  }
end

#path_with_parts(overrides = {}) ⇒ Object



76
77
78
79
80
81
82
# File 'app/models/event_calendar_page.rb', line 76

def path_with_parts(overrides={})
  parts = path_parts.merge(overrides)
  page = parts.delete(:page)
  path = parts.delete(:path)
  parts[:month] = month_names[parts[:month]].downcase unless parts[:month].blank? || parts[:month] =~ /[a-zA-Z]/
  clean_path([path, parts.values, page].select{|p| !p.blank?}.join('/'))
end

#read_parameters(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/event_calendar_page.rb', line 25

def read_parameters(path)
  @calendar_parameters = []
  unless path.blank?
    parts = path.split(/\/+/)
    @calendar_page = parts.pop if parts.last =~ /^\d{1,3}$/
    @period = {}
    parts.each do |part|
      if part.match(/^\d\d\d\d$/)
        @calendar_year = part
      elsif part.match(/^\d+$/)
        @calendar_day = part
      elsif (I18n.t 'date.month_names').include?(part.titlecase)
        @calendar_month = (I18n.t 'date.month_names').index(part.titlecase)
      elsif Calendar.categories.include?(part)
        @calendar_category = part
      elsif Calendar.slugs.include?(part)
        @calendar_slug = part
      else 
        @calendar_parameters.push(part)
      end
    end
    
    if @calendar_year && @calendar_month
      start = Date.civil(@calendar_year.to_i, @calendar_month.to_i)
      @calendar_period = CalendarPeriod.between(start, start.to_datetime.end_of_month)
    elsif calendar_year
      start = Date.civil(@calendar_year.to_i)
      @calendar_period = CalendarPeriod.between(start, start.to_datetime.end_of_year)
    end

    @calendar_parameters
  end
end