Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Incident.Impact type into an enumeration #519

Merged
merged 4 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes to Mapbox Directions for Swift

## main

* This library requires Turf v2.0.0-alpha.2. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517))
* This library does not support tvOS, watchOS, or Linux. Support for these platforms will be restored before the final release. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))

## v1.2.0

### Packaging
Expand Down
22 changes: 18 additions & 4 deletions Sources/MapboxDirections/Incident.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ public struct Incident: Codable, Equatable {
/// Weather
case weather = "weather"
}


/// Represents the impact of the incident on local traffic.
public enum Impact: String, Codable {
/// Unknown impact
case unknown
/// Critical impact
case critical
/// Major impact
case major
/// Minor impact
case minor
/// Low impact
case low
}

/// Incident identifier
public var identifier: String
/// The kind of an incident
Expand All @@ -69,7 +83,7 @@ public struct Incident: Codable, Equatable {
/// Date when incident shall end.
public var endDate: Date
/// Shows severity of an incident. May be not available for all incident types.
public var impact: String?
public var impact: Impact?
/// Provides additional classification of an incident. May be not available for all incident types.
public var subtype: String?
/// Breif description of the subtype. May be not available for all incident types and is not available if `subtype` is `nil`
Expand All @@ -91,7 +105,7 @@ public struct Incident: Codable, Equatable {
creationDate: Date,
startDate: Date,
endDate: Date,
impact: String?,
impact: Impact?,
subtype: String?,
subtypeDescription: String?,
alertCodes: Set<Int>,
Expand Down Expand Up @@ -142,7 +156,7 @@ public struct Incident: Codable, Equatable {
debugDescription: "`Intersection.endTime` is encoded with invalid format.")
}

impact = try container.decodeIfPresent(String.self, forKey: .impact)
impact = try container.decodeIfPresent(Impact.self, forKey: .impact)
subtype = try container.decodeIfPresent(String.self, forKey: .subtype)
subtypeDescription = try container.decodeIfPresent(String.self, forKey: .subtypeDescription)
alertCodes = try container.decode(Set<Int>.self, forKey: .alertCodes)
Expand Down
1 change: 1 addition & 0 deletions Tests/MapboxDirectionsTests/RouteStepTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class RouteStepTests: XCTestCase {
XCTAssertNotNil(newRoute)

XCTAssert(newRoute!.legs.first!.incidents!.first!.kind == Incident.Kind.miscellaneous)
XCTAssert(newRoute!.legs.first!.incidents!.first!.impact == Incident.Impact.minor)
XCTAssert(newRoute!.legs.first!.incidents![0].lanesBlocked!.contains(.right))
XCTAssertNil(newRoute!.legs.first!.incidents![1].lanesBlocked)
XCTAssert(newRoute!.legs.first!.incidents![2].lanesBlocked!.isEmpty)
Expand Down