lib/google/apis/calendar_v3/event.rb in zoom_launcher-0.1.1 vs lib/google/apis/calendar_v3/event.rb in zoom_launcher-0.2.0
- old
+ new
@@ -2,18 +2,25 @@
module Google
module Apis
module CalendarV3
class Event
- MEETING_URL_REGEX = %r{https://.*\.zoom\.us/j/\d+}
+ MEETING_URL_REGEX = %r{https://.*?\.zoom\.us/(?:j/(\d+)|my/(\S+))}
include ActionView::Helpers::DateHelper
+ def meeting_id
+ @meeting_id ||= (matches[1] || matches[2])
+ end
+
def meeting_url
- matches = (location + description).match(MEETING_URL_REGEX)
- matches[0] if matches
+ @meeting_url ||= URI(matches[0]) if matches
end
+ def zoom_url
+ "zoommtg://zoom.us/join?confno=#{meeting_id}" if meeting_id && !vanity_url?
+ end
+
def already_started?
start.date_time <= DateTime.now
end
def more_than_five_minutes_from_now?
@@ -25,9 +32,19 @@
if already_started?
"#{distance} ago".bold.red
else
"in #{distance}".bold
end
+ end
+
+ private
+
+ def matches
+ @matches ||= "#{location} #{description}".match(MEETING_URL_REGEX)
+ end
+
+ def vanity_url?
+ meeting_id && meeting_id !~ /\A\d+\z/
end
end
end
end
end