class MonthModel
Attributes
api_key[RW]
calendar_id[RW]
delta_start_of_weekday_from_sunday[RW]
google_calendar_base_path[RW]
maps_query_host[RW]
months_grouped_events[RW]
months_multiday_events[RW]
months_view_dates[RW]
Attributes one needs to access from the “outside”
Public Class Methods
address_to_maps_path(address)
click to toggle source
# File lib/raigoocal/month_model.rb, line 93 def self.address_to_maps_path(address) URI::HTTP.build( host: maps_query_host, query: { q: address.force_encoding("UTF-8").gsub(" ", "+") }.to_query).to_s end
current_month_end(current_shift_factor, today_date = Date.today)
click to toggle source
# File lib/raigoocal/month_model.rb, line 130 def self.current_month_end(current_shift_factor, today_date = Date.today) (today_date + (current_shift_factor.to_i).month).end_of_month end
current_month_start(current_shift_factor, today_date = Date.today)
click to toggle source
# File lib/raigoocal/month_model.rb, line 127 def self.current_month_start(current_shift_factor, today_date = Date.today) (today_date + (current_shift_factor.to_i).month).beginning_of_month end
emphasize_date(check_date, emphasized_date, emphasized, regular)
click to toggle source
# File lib/raigoocal/month_model.rb, line 73 def self.emphasize_date(check_date, emphasized_date, emphasized, regular) check_date.to_date == emphasized_date.to_date ? emphasized : regular end
find_best_fit_for_day(first_weekday, day, event_heap)
click to toggle source
# File lib/raigoocal/month_model.rb, line 41 def self.find_best_fit_for_day(first_weekday, day, event_heap) best_fit = event_heap.select{ |event| (day == first_weekday ? (event.dtstart <= day && event.dtend >= day) : (event.dtstart == day)) }.sort_by{ |event| [event.dtstart.to_time.to_i, -event.dtend.to_time.to_i] }.first end
multiday_event_cutoff(cutoff_start_condition, cutoff_end_condition, cutoff_start_style, cutoff_both_style, cutoff_end_style)
click to toggle source
# File lib/raigoocal/month_model.rb, line 77 def self.multiday_event_cutoff(cutoff_start_condition, cutoff_end_condition, cutoff_start_style, cutoff_both_style, cutoff_end_style) if (cutoff_start_condition && cutoff_end_condition) cutoff_both_style elsif (cutoff_start_condition) cutoff_start_style elsif (cutoff_end_condition) cutoff_end_style else '' end end
new(json_config)
click to toggle source
# File lib/raigoocal/month_model.rb, line 10 def initialize(json_config) json_parsed = JSON.parse(json_config) self.google_calendar_base_path = json_parsed["calendar"]["google_calendar_api_host_base_path"] self.calendar_id = json_parsed["calendar"]["calendar_id"] self.api_key = json_parsed["calendar"]["api_key"] self.summary_teaser_length = json_parsed["month"]["summary_teaser_length_in_characters"].to_i self.delta_start_of_weekday_from_sunday = json_parsed["month"]["delta_start_of_weekday_from_sunday"].to_i self.maps_query_host = json_parsed["general"]["maps_query_host"] end
summary_title(event)
click to toggle source
# File lib/raigoocal/month_model.rb, line 89 def self.summary_title(event) event.summary.to_s.force_encoding("UTF-8") + "\n" + event.location.to_s.force_encoding("UTF-8") + "\n" + event.description.to_s.force_encoding("UTF-8") end
weeks_grouped_multiday_events(months_multiday_events, first_weekday, last_weekday)
click to toggle source
# File lib/raigoocal/month_model.rb, line 37 def self.weeks_grouped_multiday_events(months_multiday_events, first_weekday, last_weekday) weeks_events = months_multiday_events.select{ |event| event.dtend > first_weekday && event.dtstart <= last_weekday } end
weeks_in_months_view_dates(months_view_dates)
click to toggle source
# File lib/raigoocal/month_model.rb, line 123 def self.weeks_in_months_view_dates(months_view_dates) months_view_dates.length.div 7 end
Public Instance Methods
ahead_path(page_path, current_shift_factor)
click to toggle source
# File lib/raigoocal/month_model.rb, line 52 def ahead_path(page_path, current_shift_factor) month_shift_path(page_path, current_shift_factor, 1) end
before_path(page_path, current_shift_factor)
click to toggle source
# File lib/raigoocal/month_model.rb, line 49 def before_path(page_path, current_shift_factor) month_shift_path(page_path, current_shift_factor, -1) end
current_shift_for_agenda(current_shift_factor)
click to toggle source
# File lib/raigoocal/month_model.rb, line 59 def current_shift_for_agenda(current_shift_factor) today_date = Date.today current_shift_in_days = (MonthModel.current_month_start(current_shift_factor, today_date) - today_date).to_i current_shift_in_days = (MonthModel.current_month_start(current_shift_factor, today_date) + ((MonthModel.current_month_end(current_shift_factor, today_date) - MonthModel.current_month_start(current_shift_factor, today_date)).div 5) - today_date).to_i current_shift_factor_for_agenda = (current_shift_in_days.div AgendaModel.days_shift_coefficient) current_shift_factor_for_agenda end
current_shift_for_month(current_shift_factor)
click to toggle source
# File lib/raigoocal/month_model.rb, line 69 def current_shift_for_month(current_shift_factor) current_shift_factor end
grouped_events(from, to)
click to toggle source
# File lib/raigoocal/month_model.rb, line 32 def grouped_events(from, to) events = month_events(from, to) events.select { |event| event.dtstart.instance_of?(DateTime) }.sort_by{ |event| event.dtstart.localtime }.group_by { |event| event.dtstart.to_date } end
month_events(from, to)
click to toggle source
# File lib/raigoocal/month_model.rb, line 23 def month_events(from, to) EventLoaderModel.get_month_events(google_calendar_base_path, calendar_id, api_key, from, to) end
month_shift_path(page_path, current_shift_factor, shift_factor)
click to toggle source
# File lib/raigoocal/month_model.rb, line 55 def month_shift_path(page_path, current_shift_factor, shift_factor) path(page_path, s: (current_shift_factor.to_i + shift_factor.to_i).to_s) end
multiday_events(from, to)
click to toggle source
# File lib/raigoocal/month_model.rb, line 27 def multiday_events(from, to) events = month_events(from, to) events.select { |event| event.dtstart.instance_of?(Date) } end
path(page_host, params = {})
click to toggle source
# File lib/raigoocal/month_model.rb, line 45 def path(page_host, params = {}) URI::HTTP.build( host: page_host, query: { v: 'm' }.merge(params).to_query).to_s end
weekday_dates(today_date = Date.today)
click to toggle source
# File lib/raigoocal/month_model.rb, line 97 def weekday_dates(today_date = Date.today) weekdays_dates = [] first_day_of_week = today_date - (today_date.wday - self.delta_start_of_weekday_from_sunday) 7.times do |day| weekdays_dates += [first_day_of_week + day] end weekdays_dates end