Skip to content

Commit

Permalink
new cup parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ekurutepe committed Mar 1, 2020
1 parent a82ad84 commit 8f77d03
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 152 deletions.
8 changes: 8 additions & 0 deletions Iguazu.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
61 changes: 0 additions & 61 deletions Iguazu/CUP/Airport.swift

This file was deleted.

58 changes: 58 additions & 0 deletions Iguazu/CUP/CUPParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// CUPParser.swift
// Iguazu
//
// Created by Engin Kurutepe on 01.03.20.
//

import Foundation

public final class CUPParser {
static public func pointOfInterest(from row: String) -> PointOfInterest? {
let components = row.components(separatedBy: ",")
// "001SPLuesse",,XX,5208.650N,01240.100E,66m,5,,,,
guard
components.count == 11,
let latitude = Measurement<UnitAngle>(latitudeString: components[3]),
let longitude = Measurement<UnitAngle>(longitudeString: components[4]),
let elevation = Measurement<UnitLength>(components[5])
else { return nil }

return PointOfInterest(
title: components[0].replacingOccurrences(of: "\"", with: ""),
code: components[1].replacingOccurrences(of: "\"", with: ""),
country: components[2].replacingOccurrences(of: "\"", with: ""),
latitude: latitude,
longitude: longitude,
elevation: elevation,
style: PointOfInterest.Style(rawValue: Int(components[6]) ?? 0) ?? .unknown,
direction: Int(components[7]),
length: Measurement<UnitLength>(components[8]),
frequency: components[9].replacingOccurrences(of: "\"", with: ""),
description: components[10].replacingOccurrences(of: "\"", with: ""))
}
}

public struct CUPFile {
let name: String
let points: [PointOfInterest]
}

public extension CUPFile {
init?(name: String, fileURL: URL) {
self.name = name
guard let fileContents = try? String(contentsOf: fileURL) else { return nil }
let lines = fileContents.components(separatedBy: .newlines)
self.points = lines.concurrentMap { (line) -> PointOfInterest? in
CUPParser.pointOfInterest(from: line)
}
.compactMap { $0 }
}

var airports: [Airport] {
return points.filter {
[PointOfInterest.Style.airfieldGliding, .airfieldGrass, .airfieldPaved].contains($0.style)
}
}

}
86 changes: 47 additions & 39 deletions Iguazu/CUP/CUPRow.swift → Iguazu/CUP/PointOfInterest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CUPRow.swift
// PointOfInterest.swift
// Iguazu
//
// Created by Engin Kurutepe on 10.06.19.
Expand All @@ -8,49 +8,57 @@

import Foundation

struct CUPRow {
public typealias Airport = PointOfInterest
public typealias Waypoint = PointOfInterest

public struct PointOfInterest: Equatable, Codable {
// Title,Code,Country,Latitude,Longitude,Elevation,Style,Direction,Length,Frequency,Description
// "LUESSE","EDOJ",DE,5208.652N,01240.182E,65.0m,2,62,1020m,"128.755",""
let title: String
let code: String?
let country: String?
let latitude: Measurement<UnitAngle>
let longitue: Measurement<UnitAngle>
let elevation: Measurement<UnitLength>
let style: Int?
let direction: Int?
let length: Measurement<UnitLength>?
let frequency: String?
let description: String?
}

extension CUPRow {
init?(_ row: String) {
let components = row.components(separatedBy: ",")
// "001SPLuesse",,XX,5208.650N,01240.100E,66m,5,,,,
guard components.count == 11 else { return nil }
self.title = components[0].replacingOccurrences(of: "\"", with: "")
self.code = components[1].replacingOccurrences(of: "\"", with: "")
self.country = components[2].replacingOccurrences(of: "\"", with: "")
public let title: String
public let code: String?
public let country: String?
public let latitude: Measurement<UnitAngle>
public let longitude: Measurement<UnitAngle>
public let elevation: Measurement<UnitLength>
public let style: Style
public let direction: Int?
public let length: Measurement<UnitLength>?
public let frequency: String?
public let description: String?

public enum Style: Int, Codable {
case unknown = 0
case waypoint
case airfieldGrass
case outlanding
case airfieldGliding
case airfieldPaved
case mountainPass
case mountainTop
case mast
case vor
case ndb
case coolingTower
case dam
case tunnel
case bridge
case powerPlant
case castle
case intersection
}

guard let latitude = Measurement<UnitAngle>(latitudeString: components[3]) else { return nil }
public init(title: String, code: String?, country: String?, latitude: Measurement<UnitAngle>, longitude: Measurement<UnitAngle>, elevation: Measurement<UnitLength>, style: Style, direction: Int?, length: Measurement<UnitLength>?, frequency: String?, description: String?) {
self.title = title
self.code = code
self.country = country
self.latitude = latitude

guard let longitude = Measurement<UnitAngle>(longitudeString: components[4]) else { return nil }
self.longitue = longitude

guard let elevation = Measurement<UnitLength>(components[5]) else { return nil }
self.longitude = longitude
self.elevation = elevation

self.style = Int(components[6])

self.direction = Int(components[7])

self.length = Measurement<UnitLength>(components[8])

self.frequency = components[9].replacingOccurrences(of: "\"", with: "")

self.description = components[10].replacingOccurrences(of: "\"", with: "")
self.style = style
self.direction = direction
self.length = length
self.frequency = frequency
self.description = description
}
}

Expand Down
52 changes: 0 additions & 52 deletions Iguazu/CUP/Waypoint.swift

This file was deleted.

0 comments on commit 8f77d03

Please sign in to comment.