Skip to content

Commit 7c816f4

Browse files
author
Bobby Sudekum
committed
more updates
1 parent cfd379d commit 7c816f4

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

OSRMTextInstructions/OSRMTextInstructions.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ public class OSRMInstructionFormatter: Formatter {
124124
return string(for: obj, legIndex: nil, numberOfLegs: nil, roadClasses: nil, modifyValueByKey: nil)
125125
}
126126

127-
public func string(for obj: Any?, legIndex: Int?, numberOfLegs: Int?, roadClasses: RoadClasses?, modifyValueByKey: ((TokenType, String) -> String)?) -> String? {
127+
/**
128+
Creates an instruction given a step and options.
129+
130+
- parameter step:
131+
- parameter legIndex: Current leg index the user is currently on.
132+
- parameter numberOfLegs: Total number of `RouteLeg` for the given `Route`.
133+
- parameter roadClasses: Option set representing the classes of road for the `RouteStep`.
134+
- parameter modifyValueByKey: Allows for mutating the instruction at given parts of the instruction.
135+
- returns: An instruction as a `String`.
136+
*/
137+
public func string(for obj: Any?, legIndex: Int?, numberOfLegs: Int?, roadClasses: RoadClasses? = RoadClasses([]), modifyValueByKey: ((TokenType, String) -> String)?) -> String? {
128138
guard let step = obj as? RouteStep else {
129139
return nil
130140
}
@@ -179,15 +189,11 @@ public class OSRMInstructionFormatter: Formatter {
179189
// Set wayName
180190
let name = step.names?.first
181191
let ref = step.codes?.first
182-
var isMotorWay = false
192+
let isMotorway = roadClasses?.contains(.motorway) ?? false
183193

184-
if let roadClasses = roadClasses, roadClasses.contains(.motorway) {
185-
isMotorWay = true
186-
}
187-
188-
if let name = name, let ref = ref, name != ref, !isMotorWay {
194+
if let name = name, let ref = ref, name != ref, !isMotorway {
189195
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))"
190-
} else if let ref = ref, isMotorWay, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty {
196+
} else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty {
191197
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref
192198
} else if name == nil, let ref = ref {
193199
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref

0 commit comments

Comments
 (0)