Skip to content

Conversation

@bsudekum
Copy link

@bsudekum bsudekum commented Jul 20, 2017

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

if let name = name, let ref = ref, name != ref, !isMotorWay {
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;
Copy link
Member

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.


if let name = name, let ref = ref, name != ref, !isMotorWay {
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: drop CharacterSet..


if let name = name, let ref = ref, name != ref, !isMotorWay {
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 {
Copy link
Author

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?

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

@1ec5 1ec5 left a 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
Copy link
Member

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? {
Copy link
Member

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 [].

Copy link
Member

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.)

@bsudekum bsudekum merged commit a7e4167 into master Jul 21, 2017
@bsudekum bsudekum deleted the wayname-class branch July 21, 2017 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants