Skip to content

Commit 96e9ddf

Browse files
committed
Check & handle actual value types coming from icalendar gem
According to: https://github.com/icalendar/icalendar/blob/v2.12.2/lib/icalendar/event.rb
1 parent f5717da commit 96e9ddf

2 files changed

Lines changed: 15 additions & 39 deletions

File tree

lib/ingestors/event_ingestion.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def convert_event_types(input)
2929
EventTypeDictionary.instance.lookup_value(input, 'title')
3030
end
3131

32-
def convert_location(input)
33-
input
34-
end
35-
3632
def parse_dates(input, timezone = nil)
3733
Time.use_zone(timezone) do
3834
# try to split on obvious interval markers

lib/ingestors/ical_ingestor.rb

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,61 +38,41 @@ def process_icalendar(url)
3838
events = Icalendar::Event.parse(data.set_encoding('utf-8'))
3939

4040
# process each event
41-
events.each do |e|
42-
process_event(e)
41+
events.each do |ical_event|
42+
add_event(process_event(ical_event))
4343
end
4444
end
4545
# finished
4646
end
4747

4848
def process_event(calevent)
49-
# puts "calevent: #{calevent.inspect}"
5049
# set fields
5150
event = OpenStruct.new
52-
event.url = calevent.url.to_s
53-
event.title = calevent.summary.to_s
54-
event.description = process_description calevent.description
55-
56-
# puts "\n\ncalevent.description = #{calevent.description}"
57-
# puts "\n\n... converted = #{event.description}"
51+
event.url = calevent.url&.to_s
52+
event.title = calevent.summary&.to_s
53+
event.description = process_description(calevent.description)
5854

5955
event.end = calevent.dtend&.to_time
6056
unless calevent.dtstart.nil?
6157
dtstart = calevent.dtstart
6258
event.start = dtstart&.to_time
6359
tzid = dtstart.ical_params['tzid']
64-
event.timezone = tzid.first.to_s if !tzid.nil? and tzid.size > 0
60+
event.timezone = tzid.first.to_s if tzid.present?
6561
end
6662

67-
event.venue = calevent.location.to_s
68-
if calevent.location.downcase.include?('online')
69-
event.online = true
70-
event.city = nil
71-
event.postcode = nil
72-
event.country = nil
73-
else
74-
location = convert_location(calevent.location)
75-
event.city = location['suburb'] unless location['suburb'].nil?
76-
event.country = location['country'] unless location['country'].nil?
77-
event.postcode = location['postcode'] unless location['postcode'].nil?
78-
end
79-
event.keywords = []
80-
unless calevent.categories.nil? or calevent.categories.first.nil?
81-
cats = calevent.categories.first
82-
if cats.is_a?(Icalendar::Values::Helpers::Array)
83-
cats.each do |item|
84-
event.keywords << item.to_s.lstrip
85-
end
86-
else
87-
event.keywords << cats.to_s.strip
63+
if calevent.location
64+
event.venue = calevent.location.to_s
65+
if calevent.location.downcase.include?('online')
66+
event.online = true
67+
event.city = nil
68+
event.postcode = nil
69+
event.country = nil
8870
end
8971
end
9072

91-
# store event
92-
@events << event
73+
event.keywords = calevent.categories.flatten.map(&:strip)
9374

94-
# finished
95-
nil
75+
event
9676
end
9777

9878
def process_description(input)

0 commit comments

Comments
 (0)