-
Notifications
You must be signed in to change notification settings - Fork 14
Use ref when way is motorway #28
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
Conversation
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))" | ||
} else if let ref = ref, isMotorWay, let decimalRange = ref.rangeOfCharacter(from: CharacterSet.decimalDigits), !decimalRange.isEmpty { | ||
wayName = ref; |
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.
This line should call modifyValueByKey
just like the next else if
case. In fact we could combine them if that would make things clearer.
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))" | ||
} else if let ref = ref, isMotorWay, let decimalRange = ref.rangeOfCharacter(from: CharacterSet.decimalDigits), !decimalRange.isEmpty { |
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.
Nit: drop CharacterSet.
.
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))" | ||
} else if let ref = ref, isMotorWay, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty { |
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.
@1ec5 tried to do
} else if let ref = ref, isMotorWay, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty || name == nil {
But I get a test failure with this logic. Am I using ||
correctly here?
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.
I think it's also to separate these two different cases.
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.
Sure, the if let
is a good reason to leave the cases separate. If we were to combine them, we'd need to nest if statements.
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.
I think as is and not nesting is okay.
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.
A few more things to address, but this PR is nearly good to go.
|
||
if let name = name, let ref = ref, name != ref { | ||
if let roadClasses = roadClasses, roadClasses.contains(.motorway) { | ||
isMotorWay = true |
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.
This can be written more succinctly:
let isMotorway = roadClasses?.contains(.motorway) ?? false
} | ||
|
||
public func string(for obj: Any?, legIndex: Int?, numberOfLegs: Int?, modifyValueByKey: ((TokenType, String) -> String)?) -> String? { | ||
public func string(for obj: Any?, legIndex: Int?, numberOfLegs: Int?, roadClasses: RoadClasses?, modifyValueByKey: ((TokenType, String) -> String)?) -> String? { |
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.
There's no semantic difference between an empty RoadClasses ([]
) and nil, so let's make the type of the roadClasses argument required. The simpler version of this method above would pass in []
.
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.
Would you mind adding documentation for this method? (The other one above is fine, because documentation is already provided by the superclass.)
Based off of Project-OSRM/osrm-text-instructions#129
If the road class is a motorway and the ref contains a number, we should announce the ref and not the name since it could be the ceremonial name.
/cc @1ec5 @freenerd @willwhite