Module: Icalendar::Google::Helpers

Included in:
Calendar
Defined in:
lib/icalendar/google/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#google_idObject

Returns the value of attribute google_id.



7
8
9
# File 'lib/icalendar/google/helpers.rb', line 7

def google_id
  @google_id
end

#ical_urlObject

Returns the value of attribute ical_url.



7
8
9
# File 'lib/icalendar/google/helpers.rb', line 7

def ical_url
  @ical_url
end

Instance Method Details

#cidObject



9
10
11
# File 'lib/icalendar/google/helpers.rb', line 9

def cid
  Base64.encode64(@google_id.to_s).gsub(%r{\n|=+\Z}, "")
end

#eid(event) ⇒ Object



13
14
15
16
# File 'lib/icalendar/google/helpers.rb', line 13

def eid(event)
  seed = "#{event.uid.split(%r{@}).first} #{@google_id&.slice(0, 28)}"
  Base64.encode64(seed).gsub(%r{\n|=+\Z}, "")
end

#event_url(event) ⇒ Object



18
19
20
# File 'lib/icalendar/google/helpers.rb', line 18

def event_url(event)
  "https://calendar.google.com/calendar/event?eid=#{eid(event)}"
end

#events_on(date) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/icalendar/google/helpers.rb', line 22

def events_on(date)
  events.select do |event|
    start = tz.utc_to_local event.dtstart.to_datetime
    stop  = tz.utc_to_local event.dtend.to_datetime
    start.to_date <= date && date <= stop.to_date
  end
end

#google_urlObject



30
31
32
# File 'lib/icalendar/google/helpers.rb', line 30

def google_url
  "https://calendar.google.com/calendar/r?cid=#{cid}"
end

#tzObject



34
35
36
# File 'lib/icalendar/google/helpers.rb', line 34

def tz
  TZInfo::Timezone.get(x_wr_timezone.first.to_s)
end

#webcal_urlObject



38
39
40
# File 'lib/icalendar/google/helpers.rb', line 38

def webcal_url
  ical_url&.sub(%r{\Ahttps?://}, "webcal://")
end