<%= event.start.strftime("%H:%M %Z") %> - <%= event.formatted_summary.sub(nsltv_regex, '') %> + <%= event.formatted_summary %>
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fcf1e89..9b9d542 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -171,26 +171,17 @@ module ApplicationHelper end end - def nsltv_regex - /\[NSLTV\]/i - end def upcoming_matches GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset). - upcoming. - find_all{|e| - not nsltv_regex =~ (e.summary) - }.sort_by do |event| + upcoming.sort_by do |event| event.start end end def upcoming_nsltv GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset). - upcoming. - find_all{|e| - nsltv_regex =~ (e.summary) - }.sort_by do |event| + upcoming_nsltv.sort_by do |event| event.start end end diff --git a/app/services/google_calendar.rb b/app/services/google_calendar.rb index 179e7dc..5996844 100644 --- a/app/services/google_calendar.rb +++ b/app/services/google_calendar.rb @@ -20,7 +20,15 @@ class GoogleCalendar def upcoming events.select do |event| - event.start >= (Time.zone.now - 2.hours) + event.start >= (Time.zone.now - 2.hours) && + (not event.nsltv_regex =~ event.summary) + end + end + + def upcoming_nsltv + events.select do |event| + event.start >= (Time.zone.now - 2.hours) && + event.nsltv_regex =~ (event.summary) end end @@ -111,8 +119,13 @@ class GoogleCalendar @entry["end"]["dateTime"].to_datetime.in_time_zone(@timezone_offset) end + def nsltv_regex + /\[NSLTV\]/i + end + def formatted_summary - summary.gsub(/(http\:\/\/)(.*[^)])/i, '\2').html_safe + summary.gsub(/(http\:\/\/)(.*[^)])/i, '\2'). + gsub(nsltv_regex, '').html_safe end def [](key) @@ -123,4 +136,4 @@ class GoogleCalendar self[method.to_s] end end -end \ No newline at end of file +end diff --git a/app/views/widgets/_calendar.html.erb b/app/views/widgets/_calendar.html.erb index 9dc7fbd..90ab71d 100644 --- a/app/views/widgets/_calendar.html.erb +++ b/app/views/widgets/_calendar.html.erb @@ -31,7 +31,7 @@
<%= event.start.strftime("%H:%M %Z") %> - <%= event.formatted_summary.sub(nsltv_regex, '') %> + <%= event.formatted_summary %>