Class: Teems::Models::Event

Inherits:
Data
  • Object
show all
Extended by:
Parsing
Defined in:
lib/teems/models/event.rb

Overview

Represents a calendar event from Microsoft Graph API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parsing

mention_display_name, normalize_mentions, parse_files_json, parse_mentions, parse_time, strip_html

Instance Attribute Details

#attendeesObject (readonly)

Returns the value of attribute attendees

Returns:

  • (Object)

    the current value of attendees



8
9
10
# File 'lib/teems/models/event.rb', line 8

def attendees
  @attendees
end

#body_previewObject (readonly)

Returns the value of attribute body_preview

Returns:

  • (Object)

    the current value of body_preview



8
9
10
# File 'lib/teems/models/event.rb', line 8

def body_preview
  @body_preview
end

#end_timeObject (readonly)

Returns the value of attribute end_time

Returns:

  • (Object)

    the current value of end_time



8
9
10
# File 'lib/teems/models/event.rb', line 8

def end_time
  @end_time
end

#event_typeObject (readonly)

Returns the value of attribute event_type

Returns:

  • (Object)

    the current value of event_type



8
9
10
# File 'lib/teems/models/event.rb', line 8

def event_type
  @event_type
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



8
9
10
# File 'lib/teems/models/event.rb', line 8

def id
  @id
end

#importanceObject (readonly)

Returns the value of attribute importance

Returns:

  • (Object)

    the current value of importance



8
9
10
# File 'lib/teems/models/event.rb', line 8

def importance
  @importance
end

#is_all_dayObject (readonly)

Returns the value of attribute is_all_day

Returns:

  • (Object)

    the current value of is_all_day



8
9
10
# File 'lib/teems/models/event.rb', line 8

def is_all_day
  @is_all_day
end

#is_cancelledObject (readonly)

Returns the value of attribute is_cancelled

Returns:

  • (Object)

    the current value of is_cancelled



8
9
10
# File 'lib/teems/models/event.rb', line 8

def is_cancelled
  @is_cancelled
end

#locationObject (readonly)

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



8
9
10
# File 'lib/teems/models/event.rb', line 8

def location
  @location
end

#online_meeting_urlObject (readonly)

Returns the value of attribute online_meeting_url

Returns:

  • (Object)

    the current value of online_meeting_url



8
9
10
# File 'lib/teems/models/event.rb', line 8

def online_meeting_url
  @online_meeting_url
end

#organizerObject (readonly)

Returns the value of attribute organizer

Returns:

  • (Object)

    the current value of organizer



8
9
10
# File 'lib/teems/models/event.rb', line 8

def organizer
  @organizer
end

#response_statusObject (readonly)

Returns the value of attribute response_status

Returns:

  • (Object)

    the current value of response_status



8
9
10
# File 'lib/teems/models/event.rb', line 8

def response_status
  @response_status
end

#sensitivityObject (readonly)

Returns the value of attribute sensitivity

Returns:

  • (Object)

    the current value of sensitivity



8
9
10
# File 'lib/teems/models/event.rb', line 8

def sensitivity
  @sensitivity
end

#show_asObject (readonly)

Returns the value of attribute show_as

Returns:

  • (Object)

    the current value of show_as



8
9
10
# File 'lib/teems/models/event.rb', line 8

def show_as
  @show_as
end

#start_timeObject (readonly)

Returns the value of attribute start_time

Returns:

  • (Object)

    the current value of start_time



8
9
10
# File 'lib/teems/models/event.rb', line 8

def start_time
  @start_time
end

#subjectObject (readonly)

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



8
9
10
# File 'lib/teems/models/event.rb', line 8

def subject
  @subject
end

Class Method Details

.core_attrs(data) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/teems/models/event.rb', line 36

def self.core_attrs(data)
  {
    id: data['id'],
    subject: data['subject'] || '(No subject)',
    start_time: parse_time(data.dig('start', 'dateTime')),
    end_time: parse_time(data.dig('end', 'dateTime')),
    location: data.dig('location', 'displayName'),
    is_all_day: data['isAllDay'] || false,
    organizer: parse_organizer(data['organizer']),
    attendees: parse_attendees(data['attendees'])
  }
end

.detail_attrs(data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/teems/models/event.rb', line 49

def self.detail_attrs(data)
  {
    body_preview: data['bodyPreview'] || strip_html(data.dig('body', 'content')),
    online_meeting_url: data.dig('onlineMeeting', 'joinUrl'),
    show_as: data['showAs'],
    importance: data['importance'],
    is_cancelled: data['isCancelled'] || false,
    response_status: data.dig('responseStatus', 'response'),
    sensitivity: data['sensitivity'],
    event_type: data['type']
  }
end

.event_attrs(data) ⇒ Object



32
33
34
# File 'lib/teems/models/event.rb', line 32

def self.event_attrs(data)
  core_attrs(data).merge(detail_attrs(data))
end

.from_api(data) ⇒ Object



28
29
30
# File 'lib/teems/models/event.rb', line 28

def self.from_api(data)
  new(**event_attrs(data))
end

.parse_attendees(attendees_data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/teems/models/event.rb', line 69

def self.parse_attendees(attendees_data)
  return [] unless attendees_data.is_a?(Array)

  attendees_data.map do |att_data|
    email_data = att_data['emailAddress'] || {}
    {
      name: email_data['name'],
      email: email_data['address'],
      type: att_data['type'],
      response: att_data.dig('status', 'response')
    }
  end
end

.parse_organizer(organizer_data) ⇒ Object



62
63
64
65
66
67
# File 'lib/teems/models/event.rb', line 62

def self.parse_organizer(organizer_data)
  return nil unless organizer_data

  email_data = organizer_data['emailAddress'] || {}
  { name: email_data['name'], email: email_data['address'] }
end

Instance Method Details

#accepted_attendeesObject



118
# File 'lib/teems/models/event.rb', line 118

def accepted_attendees = attendees.select { |att| att[:response] == 'accepted' }

#all_day?Boolean

Returns:

  • (Boolean)


89
# File 'lib/teems/models/event.rb', line 89

def all_day? = is_all_day

#cancelled?Boolean

Returns:

  • (Boolean)


90
# File 'lib/teems/models/event.rb', line 90

def cancelled? = is_cancelled

#create_summary_linesObject



108
109
110
111
112
113
114
# File 'lib/teems/models/event.rb', line 108

def create_summary_lines
  lines = []
  lines << date_display if date_display
  lines << "Location: #{location}" if location && !location.empty?
  lines << "Teams link: #{online_meeting_url}" if online_meeting_url
  lines
end

#date_displayObject



100
101
102
103
104
105
106
# File 'lib/teems/models/event.rb', line 100

def date_display
  if all_day?
    "#{start_time&.strftime('%Y-%m-%d')} (all day)"
  elsif start_time && end_time
    "#{start_time.strftime('%Y-%m-%d %H:%M')}-#{end_time.strftime('%H:%M')}"
  end
end

#declined_attendeesObject



119
# File 'lib/teems/models/event.rb', line 119

def declined_attendees = attendees.select { |att| att[:response] == 'declined' }

#optional_attendeesObject



117
# File 'lib/teems/models/event.rb', line 117

def optional_attendees = attendees.select { |att| att[:type] == 'optional' }

#pending_attendeesObject



121
# File 'lib/teems/models/event.rb', line 121

def pending_attendees = attendees.select { |att| PENDING_RESPONSES.include?(att[:response]) }

#recurring?Boolean

Returns:

  • (Boolean)


91
# File 'lib/teems/models/event.rb', line 91

def recurring? = %w[occurrence exception].include?(event_type)

#required_attendeesObject



116
# File 'lib/teems/models/event.rb', line 116

def required_attendees = attendees.select { |att| att[:type] == 'required' }

#short_hashObject



83
# File 'lib/teems/models/event.rb', line 83

def short_hash = Digest::SHA256.hexdigest(id.to_s)[0, 6]

#tentative_attendeesObject



120
# File 'lib/teems/models/event.rb', line 120

def tentative_attendees = attendees.select { |att| att[:response] == 'tentativelyAccepted' }

#time_range_displayObject



93
94
95
96
97
98
# File 'lib/teems/models/event.rb', line 93

def time_range_display
  return 'ALL DAY' if all_day?
  return '' unless start_time && end_time

  "#{start_time.strftime('%H:%M')}-#{end_time.strftime('%H:%M')}"
end

#to_json_hashObject



85
86
87
# File 'lib/teems/models/event.rb', line 85

def to_json_hash
  to_h.merge(start_time: start_time&.iso8601, end_time: end_time&.iso8601)
end