-
Notifications
You must be signed in to change notification settings - Fork 88
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
Route Alerts Refinement #506
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1676e49
vk-482-route-alerts: updated code docs for route-alert related items
Udumft 3d2a0c7
vk-482-route-alerts: refined Incident properties
Udumft 1010e47
vk-482-route-alerts: renamed Incident date typed properties
Udumft 5018d79
vk-482-route-alerts: removed nodoc tags
Udumft 4523d66
vk-482-route-alerts: CHANGELOG updated
Udumft 83d60ac
vk-482-route-alerts: refined Incident properties, added BlockedLane e…
Udumft f5511e6
vk-482-route-alerts: added unit test for Incidents coding
Udumft 126f885
vk-482-route-alerts: fixture added
Udumft 9e3ecaf
vk-482-route-alerts: correct Incident BlockedLane enum by lowercasing…
Udumft 7ab57b8
vk-482-route-alerts: added ISO8601 date formatter extension
Udumft a654509
vk-482-route-alerts: unit test corrected
Udumft 138966d
vk-482-route-alerts: reverted custom Date ISO8601 formatter.
Udumft f87f100
vk-482-route-alerts: lowercased Incidents.Kind enum cases. Updated co…
Udumft e8bce6d
vk-482-route-alerts: refactored BlockedLanes to become an Options Set…
Udumft 25cd3c0
482-route-alerts: doc and CHANGELOG corrections
Udumft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
|
||
import Foundation | ||
|
||
/// Defines a lane affected by the `Incident` | ||
public struct BlockedLanes: OptionSet, CustomStringConvertible { | ||
public var rawValue: Int | ||
var stringKey: String? | ||
|
||
public init(rawValue: Int) { | ||
self.init(rawValue: rawValue, key: nil) | ||
} | ||
|
||
init(rawValue: Int, key: String?) { | ||
self.rawValue = rawValue | ||
self.stringKey = key | ||
} | ||
|
||
/// Left lane | ||
public static let left = BlockedLanes(rawValue: 1 << 0, key: "LEFT") | ||
/// Left center lane | ||
/// | ||
/// Usually refers to the second lane from left on a four-lane highway | ||
public static let leftCenter = BlockedLanes(rawValue: 1 << 1, key: "LEFT CENTER") | ||
/// Left turn lane | ||
public static let leftTurnLane = BlockedLanes(rawValue: 1 << 2, key: "LEFT TURN LANE") | ||
/// Center lane | ||
public static let center = BlockedLanes(rawValue: 1 << 3, key: "CENTER") | ||
/// Right lane | ||
public static let right = BlockedLanes(rawValue: 1 << 4, key: "RIGHT") | ||
/// Right center lane | ||
/// | ||
/// Usually refers to the second lane from right on a four-lane highway | ||
public static let rightCenter = BlockedLanes(rawValue: 1 << 5, key: "RIGHT CENTER") | ||
/// Right turn lane | ||
public static let rightTurnLane = BlockedLanes(rawValue: 1 << 6, key: "RIGHT TURN LANE") | ||
/// High occupancy vehicle lane | ||
public static let highOccupancyVehicle = BlockedLanes(rawValue: 1 << 7, key: "HOV") | ||
/// Side lane | ||
public static let side = BlockedLanes(rawValue: 1 << 8, key: "SIDE") | ||
/// Shoulder lane | ||
public static let shoulder = BlockedLanes(rawValue: 1 << 9, key: "SHOULDER") | ||
/// Median lane | ||
public static let median = BlockedLanes(rawValue: 1 << 10, key: "MEDIAN") | ||
/// 1st Lane. | ||
public static let lane1 = BlockedLanes(rawValue: 1 << 11, key: "1") | ||
/// 2nd Lane. | ||
public static let lane2 = BlockedLanes(rawValue: 1 << 12, key: "2") | ||
/// 3rd Lane. | ||
public static let lane3 = BlockedLanes(rawValue: 1 << 13, key: "3") | ||
/// 4th Lane. | ||
public static let lane4 = BlockedLanes(rawValue: 1 << 14, key: "4") | ||
/// 5th Lane. | ||
public static let lane5 = BlockedLanes(rawValue: 1 << 15, key: "5") | ||
/// 6th Lane. | ||
public static let lane6 = BlockedLanes(rawValue: 1 << 16, key: "6") | ||
/// 7th Lane. | ||
public static let lane7 = BlockedLanes(rawValue: 1 << 17, key: "7") | ||
/// 8th Lane. | ||
public static let lane8 = BlockedLanes(rawValue: 1 << 18, key: "8") | ||
/// 9th Lane. | ||
public static let lane9 = BlockedLanes(rawValue: 1 << 19, key: "9") | ||
/// 10th Lane. | ||
public static let lane10 = BlockedLanes(rawValue: 1 << 20, key: "10") | ||
|
||
static var allLanes: [BlockedLanes] { | ||
return [.left, .leftCenter, .leftTurnLane, .center, .right, .rightCenter, .rightTurnLane, .highOccupancyVehicle, .side, .shoulder, .median, .lane1, .lane2, .lane3, .lane4, .lane5, .lane6, .lane7, .lane8, .lane9, .lane10] | ||
} | ||
|
||
/** | ||
Creates a `BlockedLanes` given an array of strings. | ||
|
||
Resulting options set will only contain known values. If string description does not match any known `Blocked Lane` identifier - it will be ignored. | ||
*/ | ||
public init?(descriptions: [String]) { | ||
var blockedLanes: BlockedLanes = [] | ||
Self.allLanes.forEach { | ||
if descriptions.contains($0.stringKey!) { | ||
blockedLanes.insert($0) | ||
} | ||
} | ||
self.init(rawValue: blockedLanes.rawValue) | ||
} | ||
|
||
/** | ||
String representation of `BlockedLanes` options set. | ||
|
||
Resulting description contains only texts for known options. Custom options will be ignored if any. | ||
*/ | ||
public var description: String { | ||
var descriptions: [String] = [] | ||
Self.allLanes.forEach { | ||
if contains($0) { | ||
descriptions.append($0.stringKey!) | ||
} | ||
} | ||
return descriptions.joined(separator: ",") | ||
} | ||
} | ||
|
||
extension BlockedLanes: Codable { | ||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(description.components(separatedBy: ",").filter { !$0.isEmpty }) | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let descriptions = try container.decode([String].self) | ||
if let roadClasses = BlockedLanes(descriptions: descriptions){ | ||
self = roadClasses | ||
} | ||
else{ | ||
throw DirectionsError.invalidResponse(nil) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool, thanks for taking care of turning this type into an option set.