@@ -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