class AgendaModel
Attributes
api_key[RW]
calendar_id[RW]
days_shift_coefficient[RW]
display_day_count[RW]
Attributes one needs to access from the “outside”
google_calendar_base_path[RW]
maps_query_host[RW]
Public Class Methods
address_to_maps_path(address)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 72 def self.address_to_maps_path(address) URI::HTTP.build( host: self.maps_query_host, query: { q: address.force_encoding("UTF-8").gsub(" ", "+") }.to_query).to_s end
emphasize_date(check_date, emphasized_date, emphasized, regular)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 64 def self.emphasize_date(check_date, emphasized_date, emphasized, regular) check_date.to_date == emphasized_date.to_date ? emphasized : regular end
new(json_config)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 8 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.display_day_count = json_parsed["agenda"]["display_day_count"].to_i self.days_shift_coefficient = json_parsed["agenda"]["days_shift_coefficient"].to_i self.maps_query_host = json_parsed["general"]["maps_query_host"] end
summary_title(event)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 68 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
Public Instance Methods
agenda_events(from, to, today)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 20 def agenda_events(from, to, today) EventLoaderModel.get_agenda_events(google_calendar_base_path, calendar_id, api_key, from, to) end
ahead_path(page_host, current_shift_factor)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 38 def ahead_path(page_host, current_shift_factor) week_shift_path(page_host, current_shift_factor, +1) end
before_path(page_host, current_shift_factor)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 35 def before_path(page_host, current_shift_factor) week_shift_path(page_host, current_shift_factor, -1) end
current_end_date(current_shift_factor, today_date = Date.today)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 60 def current_end_date(current_shift_factor, today_date = Date.today) today_date + (current_shift_factor.to_i * self.days_shift_coefficient + self.display_day_count).days end
current_shift_for_agenda(current_shift_factor)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 45 def current_shift_for_agenda(current_shift_factor) current_shift_factor end
current_shift_for_month(current_shift_factor, today_date = Date.today)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 48 def current_shift_for_month(current_shift_factor, today_date = Date.today) date_span = (current_end_date(current_shift_factor, today_date) - current_start_date(current_shift_factor, today_date)).to_i midway_date = (current_start_date(current_shift_factor, today_date) + (date_span / 2)) current_month_shift = ((midway_date.year * 12 + midway_date.month) - (today_date.year * 12 + today_date.month)).to_i current_month_shift end
current_start_date(current_shift_factor, today_date = Date.today)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 57 def current_start_date(current_shift_factor, today_date = Date.today) today_date + (current_shift_factor.to_i * self.days_shift_coefficient).days end
get_days_grouped_events(from, to, today)
click to toggle source
best if called in a cached block
# File lib/raigoocal/agenda_model.rb, line 25 def get_days_grouped_events(from, to, today) events = agenda_events(from, to, today) events.group_by { |event| event.dtstart.to_date } end
path(page_host, params = {})
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 31 def path(page_host, params = {}) URI::HTTP.build( host: page_host, query: { v: 'a' }.merge(params).to_query).to_s end
week_shift_path(page_host, current_shift_factor, shift_factor)
click to toggle source
# File lib/raigoocal/agenda_model.rb, line 41 def week_shift_path(page_host, current_shift_factor, shift_factor) path(page_host , s: (current_shift_factor.to_i + shift_factor.to_i).to_s) end