Class: FacebookGoogleCalendarSync::EventConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_google_calendar_sync/event_converter.rb

Constant Summary collapse

STATUS_MAPPINGS =
{'NEEDS-ACTION' => 'needsAction', 'ACCEPTED' => 'accepted'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(facebook_event, google_calendar_id, timezone) ⇒ EventConverter

Returns a new instance of EventConverter.



8
9
10
11
12
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 8

def initialize facebook_event, google_calendar_id, timezone
  @facebook_event = facebook_event
  @google_calendar_id = google_calendar_id
  @timezone = timezone
end

Instance Attribute Details

#facebook_eventObject

Returns the value of attribute facebook_event.



5
6
7
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 5

def facebook_event
  @facebook_event
end

#google_calendar_idObject

Returns the value of attribute google_calendar_id.



5
6
7
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 5

def google_calendar_id
  @google_calendar_id
end

#timezoneObject

Returns the value of attribute timezone.



5
6
7
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 5

def timezone
  @timezone
end

Instance Method Details

#attendeesObject



44
45
46
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 44

def attendees
  [{"email"=>google_calendar_id, 'responseStatus' => partstat}]
end

#createdObject



26
27
28
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 26

def created
  facebook_event.created
end

#descriptionObject



48
49
50
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 48

def description
  "#{facebook_event.description}\n\nOrganiser: #{organiser_name}"
end

#last_modifiedObject



18
19
20
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 18

def last_modified
  facebook_event.last_modified.convert_time_zone(timezone)
end

#organiserObject



65
66
67
68
69
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 65

def organiser
  {
    'email' => '[email protected]',
  }
end

#organiser_nameObject



60
61
62
63
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 60

def organiser_name
  matches = facebook_event.organizer_property.to_s.scan(/CN=(.*):MAILTO:(.*)/).flatten
  matches[0]
end

#partstatObject



52
53
54
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 52

def partstat
  STATUS_MAPPINGS[facebook_event.to_s.scan(/PARTSTAT::(.*)/).flatten.first()]
end

#summaryObject



22
23
24
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 22

def summary
  facebook_event.summary
end

#to_hashObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 30

def to_hash
  {
     'summary' => facebook_event.summary,
     'start' => date_hash(facebook_event.dtstart),
     'end' => date_hash(facebook_event.dtend),
     'iCalUID' => facebook_event.uid,
     'description' => description,
     'location' => facebook_event.location,
     'organizer' => organiser,
     'attendees' => attendees,
     'transparency' => transparency
  }
end

#transparencyObject



56
57
58
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 56

def transparency
  partstat == 'accepted' ? 'opaque' : 'transparent'
end

#uidObject



14
15
16
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 14

def uid
  facebook_event.uid
end