summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-04-03 18:50:36 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-04-03 18:50:36 +0200
commit7e92994838ae4c4548c2569f303340756793a0f4 (patch)
treef7ae90bd144a5ee06da386d97b0468e1062a991c /lib/Travel
parent99ea553eadf3dbfea7c5f0948115012617195b26 (diff)
Journey: Add operators accessor
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index afdea48..986582a 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -8,7 +8,7 @@ use 5.014;
use parent 'Class::Accessor';
use DateTime::Format::Strptime;
-use List::Util qw(any);
+use List::Util qw(any uniq);
use Travel::Status::DE::HAFAS::Stop;
our $VERSION = '6.00';
@@ -270,6 +270,23 @@ sub messages {
return;
}
+sub operators {
+ my ($self) = @_;
+
+ if ( $self->{operators} ) {
+ return @{ $self->{operators} };
+ }
+
+ $self->{operators} = [
+ uniq map { ( $_->prod_arr // $_->prod_dep )->operator } grep {
+ ( $_->prod_arr or $_->prod_dep )
+ and ( $_->prod_arr // $_->prod_dep )->operator
+ } $self->route
+ ];
+
+ return @{ $self->{operators} };
+}
+
sub polyline {
my ($self) = @_;
@@ -549,7 +566,13 @@ detailed delay reasons (e.g. "switch damage between X and Y, expect delays").
=item $journey->operator
The operator responsible for this journey. Returns undef
-if the backend does not provide an operator.
+if the backend does not provide an operator. Note that the operator may
+change along the journey -- in this case, the returned operator depends on
+the backend and appears to be the first one in most cases.
+
+=item $journey->operators
+
+List of all operators observed along the journey.
=item $journey->station (station only)