@@ -184,39 +184,37 @@ class ScheduleParser {
184184
185185 }
186186
187+
187188 // MARK: Parsing
188- // Postcondition: Events that are not fully defined will be SILENTLY SKIPPED.
189- // @FIXME: Add support for empty-description events!!
189+
190190 // Sets event data as a field
191+ // @FIXME: Bug when setting date ("monday 1am") as date is set then converted? something like that
192+ // Day index appears to be fine.
191193 private static func parseEvents( data: Welcome ) {
192194
195+ var currentEvent = Event ( )
196+
193197 // The parse loop
194198 // @FIXME: Using 3rd sheet as test, convert to 1st for production
195- for (rowIndex, rowData) in data. sheets [ 2 ] . data [ 0 ] . rowData. enumerated ( ) {
199+ for (rowIndex, rowData) in data. sheets [ 0 ] . data [ 0 ] . rowData. enumerated ( ) {
196200
197201 // See comment below for how this skip variable functions
198202 var skip = false
199- var currentEvent = Event ( )
200203
201204 // Use indexing to more accurately determine column purpose
202205 for columnIndex in 0 ..< rowData. columns. count {
203206
204207 // Skip section day header title ("Saturday", "Sunday").
205- // "section" 0 is Saturday, 1 is sunday
208+ // "section" 0 is Saturday, 1 is Sunday
206209 // Note that this is NOT the same as Table View sections -- remember, we are only in the model!
207210 // (and that's how it was named on the spreadsheet)
208211 if skip {
209212 skip = false
210213 continue
211214 }
212215
213- // Check for valid text
214- // (And convinence so we don't have to read this mess of an index)
215- // Note: error message is printed in SHEETS index (1-based) for easier debugging there.
216- guard let cellText = rowData. columns [ columnIndex] . userEnteredValue? . stringValue else {
217- print ( " Unable to parse cell value \( rowData. columns [ columnIndex] ) at row \( rowIndex + 1 ) , column \( columnIndex + 1 ) " )
218- continue
219- }
216+ // Only set if text is valid, otherwise, #emptystring
217+ let cellText = rowData. columns [ columnIndex] . userEnteredValue? . stringValue ?? " "
220218
221219 // Now, onto the core parsing.
222220
@@ -241,21 +239,11 @@ class ScheduleParser {
241239 // Now, figure out what part of the Event struct we're filling.
242240 switch columnIndex {
243241 case 0 :
244- // This is the ScheduleKeyword, handled in the above switch statement
245- // However we use this opportunity to set the schedule index tag from the previous row.
246- currentEvent. section = sectionIndex
247- break
248242
249- case 1 : currentEvent. time = stringToDate ( cellText) ?? Date ( )
250- case 2 : currentEvent. title = cellText
251- case 3 : currentEvent. location = cellText
252- case 4 : currentEvent. description = cellText
253- case 5 : currentEvent. uuid = cellText
254-
255- // Once we reach the fifth case, we know we're at the end of the data for a cell.
256- // This means that now we can reset the event!
257- self . events. append ( currentEvent)
258- currentEvent = Event ( )
243+ guard rowIndex > 1 || !currentEvent. title. isEmpty else {
244+ print ( " broken like me right now " )
245+ break
246+ }
259247
260248 // However, we also need to figure out what UI section the data is in.
261249 // Assuming events are in cronological order:
@@ -269,6 +257,22 @@ class ScheduleParser {
269257 // Otherwise, keep them in the same section.
270258 }
271259 }
260+
261+ // This is the ScheduleKeyword, handled in the above switch statement
262+ // However we use this opportunity to set the schedule index tag from the previous row.
263+ currentEvent. section = sectionIndex
264+
265+ // Append the completed event
266+ self . events. append ( currentEvent)
267+
268+ // Reset event manually
269+ currentEvent = Event ( )
270+
271+ case 1 : currentEvent. time = stringToDate ( cellText) ?? Date ( )
272+ case 2 : currentEvent. title = cellText
273+ case 3 : currentEvent. location = cellText
274+ case 4 : currentEvent. description = cellText
275+ case 5 : currentEvent. uuid = cellText
272276 default : break
273277 }
274278
@@ -311,7 +315,7 @@ class ScheduleParser {
311315 }
312316
313317 // Helper function for debugging JSON
314- private func prettyPrintJSON( data: Data ) {
318+ private static func prettyPrintJSON( data: Data ) {
315319 let json = try ? JSONSerialization . jsonObject ( with: data, options: . allowFragments)
316320
317321 guard let json2 = json else {
0 commit comments