Class: CalendarAssistant::Event

Inherits:
SimpleDelegator
  • Object
show all
Includes:
HasDuration
Defined in:
lib/calendar_assistant/event.rb

Defined Under Namespace

Modules: RealResponse, Response, Transparency, Visibility

Constant Summary collapse

PREDICATES =
{
  "response": %I[
    accepted?
    declined?
    awaiting?
    tentative?
  ],
  "temporal": %I[
    all_day?
    past?
    current?
    future?
  ],
  "visibility": %I[
    private?
    public?
    explicitly_visible?
    visible_guestlist?
  ],
  "attributes": %I[
    location_event?
    self?
    one_on_one?
    busy?
    commitment?
    recurring?
    abandoned?
    anyone_can_add_self?
    attendees_omitted?
    end_time_unspecified?
    guests_can_invite_others?
    guests_can_modify?
    guests_can_see_other_guests?
    private_copy?
    locked?
    needs_action?
  ],
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasDuration

#all_day?, cast_datetime, #contains?, #cover?, #current?, #duration, duration_in_seconds, #duration_in_seconds, #end_date, #end_time, #future?, #overlaps_end_of?, #overlaps_start_of?, #past?, #start_date, #start_time

Constructor Details

#initialize(obj, config: CalendarAssistant::Config.new) ⇒ Event

instance methods



85
86
87
88
# File 'lib/calendar_assistant/event.rb', line 85

def initialize(obj, config: CalendarAssistant::Config.new)
  super(obj)
  @config = config
end

Class Method Details

.location_event_prefix(config) ⇒ Object

class methods



74
75
76
77
78
79
80
# File 'lib/calendar_assistant/event.rb', line 74

def self.location_event_prefix(config)
  icon = config[CalendarAssistant::Config::Keys::Settings::LOCATION_ICON]
  if nickname = config[CalendarAssistant::Config::Keys::Settings::NICKNAME]
    return "#{icon} #{nickname} @ "
  end
  "#{icon} "
end

Instance Method Details

#abandoned?Boolean

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
# File 'lib/calendar_assistant/event.rb', line 154

def abandoned?
  return false if declined? || self? || response_status.nil? || !visible_guestlist?
  human_attendees.each do |attendee|
    next if attendee.self
    return false if attendee.response_status != CalendarAssistant::Event::Response::DECLINED
  end
  return true
end

#accepted?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/calendar_assistant/event.rb', line 99

def accepted?
  response_status == CalendarAssistant::Event::Response::ACCEPTED
end

#attendee(id) ⇒ Object



178
179
180
181
182
183
# File 'lib/calendar_assistant/event.rb', line 178

def attendee(id)
  return nil if attendees.nil?
  attendees.find do |attendee|
    attendee.email == id
  end
end

#av_uriObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/calendar_assistant/event.rb', line 193

def av_uri
  @av_uri ||= begin
    if conference_data && conference_data.conference_solution.name == "Zoom Meeting"
      return conference_data.entry_points.detect{|d| d.entry_point_type == "video" }.uri
    end

    description_link = CalendarAssistant::StringHelpers.find_uri_for_domain(description, "zoom.us")
    return description_link if description_link

    location_link = CalendarAssistant::StringHelpers.find_uri_for_domain(location, "zoom.us")
    return location_link if location_link

    return hangout_link if hangout_link
    nil
  end
end

#awaiting?Boolean Also known as: needs_action?

Returns:

  • (Boolean)


107
108
109
# File 'lib/calendar_assistant/event.rb', line 107

def awaiting?
  response_status == CalendarAssistant::Event::Response::NEEDS_ACTION
end

#busy?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/calendar_assistant/event.rb', line 128

def busy?
  transparency != CalendarAssistant::Event::Transparency::TRANSPARENT
end

#commitment?Boolean

Returns:

  • (Boolean)


132
133
134
135
136
# File 'lib/calendar_assistant/event.rb', line 132

def commitment?
  return false if human_attendees.nil? || human_attendees.length < 2
  return false if declined?
  true
end

#declined?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/calendar_assistant/event.rb', line 103

def declined?
  response_status == CalendarAssistant::Event::Response::DECLINED
end

#explicitly_visible?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/calendar_assistant/event.rb', line 146

def explicitly_visible?
  private? || public?
end

#human_attendeesObject



173
174
175
176
# File 'lib/calendar_assistant/event.rb', line 173

def human_attendees
  return nil if attendees.nil?
  attendees.select { |a| !a.resource }
end

#location_event?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/calendar_assistant/event.rb', line 95

def location_event?
  !!summary.try(:starts_with?, Event.location_event_prefix(@config))
end

#one_on_one?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
# File 'lib/calendar_assistant/event.rb', line 121

def one_on_one?
  return false if attendees.nil?
  return false unless attendees.any? { |a| a.self }
  return false if human_attendees.length != 2
  true
end

#other_human_attendeesObject



168
169
170
171
# File 'lib/calendar_assistant/event.rb', line 168

def other_human_attendees
  return nil if attendees.nil?
  attendees.select { |a| !a.resource && !a.self }
end

#private?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/calendar_assistant/event.rb', line 138

def private?
  visibility == CalendarAssistant::Event::Visibility::PRIVATE
end

#public?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/calendar_assistant/event.rb', line 142

def public?
  visibility == CalendarAssistant::Event::Visibility::PUBLIC
end

#recurring?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/calendar_assistant/event.rb', line 150

def recurring?
  !!recurring_event_id
end

#response_statusObject



185
186
187
188
189
190
191
# File 'lib/calendar_assistant/event.rb', line 185

def response_status
  return CalendarAssistant::Event::Response::SELF if attendees.nil?
  attendees.each do |attendee|
    return attendee.response_status if attendee.self
  end
  nil
end

#self?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/calendar_assistant/event.rb', line 117

def self?
  response_status == CalendarAssistant::Event::Response::SELF
end

#tentative?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/calendar_assistant/event.rb', line 113

def tentative?
  response_status == CalendarAssistant::Event::Response::TENTATIVE
end

#update(**args) ⇒ Object



90
91
92
93
# File 'lib/calendar_assistant/event.rb', line 90

def update(**args)
  update!(**args)
  self
end

#visible_guestlist?Boolean

Returns:

  • (Boolean)


163
164
165
166
# File 'lib/calendar_assistant/event.rb', line 163

def visible_guestlist?
  gcsog = guests_can_see_other_guests?
  gcsog.nil? ? true : !!gcsog
end