diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-11-17 18:48:14 +0100 |
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-11-17 18:48:14 +0100 |
| commit | 1fec4f8daafeefed61357ac9cb8569c1661216ce (patch) | |
| tree | e12f28be0f1f1750b9319af64e5803fb9e0842ec /lib | |
| parent | 65a08b86a13178675d40048e01abf9d6770ba11b (diff) | |
Journey: Add trip_no_at accessor
Closes #9
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm index e87a73e..e40aaaf 100644 --- a/lib/Travel/Status/DE/DBRIS/Journey.pm +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -227,6 +227,21 @@ sub trip_numbers { return @{ $self->{trip_numbers} // [] }; } +sub trip_no_at { + my ( $self, $loc, $ts ) = @_; + for my $stop ( $self->route ) { + if ( $stop->name eq $loc or $stop->eva eq $loc ) { + if ( not defined $ts + or not( $stop->sched_dep // $stop->sched_arr ) + or ( $stop->sched_dep // $stop->sched_arr )->epoch == $ts ) + { + return $stop->trip_no; + } + } + } + return; +} + sub TO_JSON { my ($self) = @_; @@ -318,6 +333,13 @@ Textual description of the departure, typically consisting of type identifier Trip number, if available. undef otherwise. +=item $journey->trip_no_at($stop, $epoch) + +Return trip number at I<$stop> (name or EVA ID), if available. Optionally, +I<$epoch> can be used to only match stops where scheduled departure or arrival +is equal to I<$epoch>. This is useful in case a trip passes the same stop +multiple times. + =item $journey->line_no Line identifier, if available. undef otherwise. Note that the line identifier |
