summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-06-08 08:29:34 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-06-08 08:29:34 +0200
commit21174bc9e0367018f28c0b5fc98d0e0fca317160 (patch)
tree7eae01acd4541162b117225bf7bda6d759380acf
parentd97790563dc97c130433cd12479cb2698c6f0201 (diff)
place_candidates, name_candidates: return Stop objects
Fixes https://github.com/derf/db-fakedisplay/issues/38 once adopted there
-rw-r--r--Changelog6
-rwxr-xr-xbin/efa-m8
-rw-r--r--lib/Travel/Status/DE/EFA.pm34
-rw-r--r--t/21-vrr-ambig.t8
4 files changed, 44 insertions, 12 deletions
diff --git a/Changelog b/Changelog
index 500d3b6..5d8a9d9 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,9 @@
+git HEAD
+
+ * Breaking change: $efa->name_candidates and $efa->place_candidates now
+ return lists of Travel::Status::DE::EFA::Stop objects rather than
+ just strings.
+
Travel::Status::DE::VRR 3.09 - Sun Mar 23 2025
* Trip: Add polyline accessor
diff --git a/bin/efa-m b/bin/efa-m
index 3d9a7f5..1890db9 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -555,11 +555,15 @@ if ( my $err = $efa->errstr ) {
if ( $efa->place_candidates ) {
say 'You might want to try one of the following places:';
- say join( "\n", $efa->place_candidates );
+ for my $candidate ( $efa->place_candidates ) {
+ printf( "%d %s\n", $candidate->id_num, $candidate->name );
+ }
}
elsif ( $efa->name_candidates ) {
say 'You might want to try one of the following names:';
- say join( "\n", $efa->name_candidates );
+ for my $candidate ( $efa->name_candidates ) {
+ printf( "%d %s\n", $candidate->id_num, $candidate->name );
+ }
}
exit 2;
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index d1b14d8..29dbf5b 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -412,15 +412,37 @@ sub check_for_ambiguous {
for my $m ( @{ $json->{dm}{message} // [] } ) {
if ( $m->{name} eq 'error' and $m->{value} eq 'name list' ) {
- $self->{errstr} = "ambiguous name parameter";
- $self->{name_candidates}
- = [ map { $_->{name} } @{ $json->{dm}{points} // [] } ];
+ $self->{errstr} = "ambiguous name parameter";
+ $self->{name_candidates} = [];
+ for my $point ( @{ $json->{dm}{points} // [] } ) {
+ my $place = $point->{ref}{place};
+ push(
+ @{ $self->{name_candidates} },
+ Travel::Status::DE::EFA::Stop->new(
+ place => $place,
+ full_name => $point->{name},
+ name => $point->{name} =~ s{\Q$place\E,? ?}{}r,
+ id_num => $point->{ref}{id},
+ )
+ );
+ }
return;
}
if ( $m->{name} eq 'error' and $m->{value} eq 'place list' ) {
- $self->{errstr} = "ambiguous name parameter";
- $self->{place_candidates}
- = [ map { $_->{name} } @{ $json->{dm}{points} // [] } ];
+ $self->{errstr} = "ambiguous name parameter";
+ $self->{place_candidates} = [];
+ for my $point ( @{ $json->{dm}{points} // [] } ) {
+ my $place = $point->{ref}{place};
+ push(
+ @{ $self->{place_candidates} },
+ Travel::Status::DE::EFA::Stop->new(
+ place => $place,
+ full_name => $point->{name},
+ name => $point->{name} =~ s{\Q$place\E,? ?}{}r,
+ id_num => $point->{ref}{id},
+ )
+ );
+ }
return;
}
}
diff --git a/t/21-vrr-ambig.t b/t/21-vrr-ambig.t
index a201d52..de03b30 100644
--- a/t/21-vrr-ambig.t
+++ b/t/21-vrr-ambig.t
@@ -27,11 +27,11 @@ is( $status->errstr, 'ambiguous name parameter', 'errstr ok' );
is_deeply( [ $status->place_candidates ], [], 'place candidates ok' );
is_deeply(
- [ $status->name_candidates ],
+ [ map { $_->id_num . ' ' . $_->full_name } $status->name_candidates ],
[
- 'Essen, Alfred-Krupp-Schule',
- 'Essen, Alfredbrücke',
- 'Essen, Alfredusbad'
+ '20009114 Essen, Alfred-Krupp-Schule',
+ '20009113 Essen, Alfredbrücke',
+ '20009115 Essen, Alfredusbad',
],
'name candidates ok'
);