Skip to content

Commit

Permalink
Merge pull request #33 from Project-OSRM/codes
Browse files Browse the repository at this point in the history
Expose refs in modifier function
  • Loading branch information
Bobby Sudekum authored Aug 18, 2017
2 parents 512530f + 1682c90 commit f15f6b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions OSRMTextInstructions/OSRMTextInstructions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ public class OSRMInstructionFormatter: Formatter {
let isMotorway = roadClasses?.contains(.motorway) ?? false

if let name = name, let ref = ref, name != ref, !isMotorway {
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))"
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.code, ref)))" : "\(name) (\(ref))"
} else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty {
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref
} else if name == nil, let ref = ref {
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref
} else {
wayName = name != nil ? modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name!))" : name! : ""
}
Expand Down Expand Up @@ -276,6 +276,7 @@ public class OSRMInstructionFormatter: Formatter {
if let tokenType = TokenType(description: token! as String) {
var replacement: String
switch tokenType {
case .code: replacement = step.codes?.first ?? ""
case .wayName: replacement = wayName
case .destination: replacement = destination
case .exitCode: replacement = exitCode
Expand Down
5 changes: 5 additions & 0 deletions OSRMTextInstructions/TokenType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum TokenType: Int, CustomStringConvertible {
case modifier
case direction
case wayPoint
case code

public init?(description: String) {
let type: TokenType
Expand All @@ -34,6 +35,8 @@ public enum TokenType: Int, CustomStringConvertible {
type = .direction
case "nth":
type = .wayPoint
case "ref":
type = .code
default:
return nil
}
Expand All @@ -60,6 +63,8 @@ public enum TokenType: Int, CustomStringConvertible {
return "direction"
case .wayPoint:
return "nth"
case .code:
return "ref"
}
}
}

0 comments on commit f15f6b4

Please sign in to comment.