From 33af8b700e663a0d65e9bc761077d08fd79e98dc Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Mon, 15 Apr 2024 19:37:03 +0200 Subject: Journey: Add product_at accessor --- lib/Travel/Status/DE/HAFAS/Journey.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm index 978268e..696841e 100644 --- a/lib/Travel/Status/DE/HAFAS/Journey.pm +++ b/lib/Travel/Status/DE/HAFAS/Journey.pm @@ -17,7 +17,7 @@ Travel::Status::DE::HAFAS::Journey->mk_ro_accessors( qw(datetime sched_datetime rt_datetime tz_offset is_additional is_cancelled is_partially_cancelled station station_eva platform sched_platform rt_platform operator - product + product product_at id name type type_long class number line line_no load delay route_end route_start origin destination direction) ); @@ -368,6 +368,16 @@ sub route_interesting { } +sub product_at { + my ( $self, $req_stop ) = @_; + for my $stop ( $self->route ) { + if ( $stop->loc->name eq $req_stop or $stop->loc->eva eq $req_stop ) { + return $stop->prod_dep // $stop->prod_arr; + } + } + return; +} + sub TO_JSON { my ($self) = @_; @@ -530,6 +540,12 @@ of transport, line number / ID, operator, ...) associated with this journey. Note that journeys may be associated with multiple products -- see also C<< $journey->route >> and C<< $stop->product >>. +=item $journey->product_at(I) + +Travel::Status::DE::HAFAS::Product(3pm) instance describing the product +associated with I (name or EVA ID). Returns undef if product or I +are unknown. + =item $journey->rt_platform (station only) Actual arrival/departure platform. -- cgit v1.2.3