Bug fix and clean up with nsltv tag.

This commit is contained in:
simplefl 2015-07-19 12:33:49 +02:00
parent f943b18c12
commit b24f808c48
3 changed files with 19 additions and 15 deletions

View file

@ -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

View file

@ -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, '<a href="\1\2">\2</a>').html_safe
summary.gsub(/(http\:\/\/)(.*[^)])/i, '<a href="\1\2">\2</a>').
gsub(nsltv_regex, '').html_safe
end
def [](key)
@ -123,4 +136,4 @@ class GoogleCalendar
self[method.to_s]
end
end
end
end

View file

@ -31,7 +31,7 @@
<div class="entry">
<p class="summary">
<span class="time"><%= event.start.strftime("%H:%M %Z") %></span>
<%= event.formatted_summary.sub(nsltv_regex, '') %>
<%= event.formatted_summary %>
</p>
</div>
<% end %>