summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2023-01-22 18:42:19 +0100
committerDaniel Friesel <derf@finalrewind.org>2023-01-22 18:42:19 +0100
commit1ee75d67d8087ba65e00d331554b28caa33682f5 (patch)
treeab8387f1434f35ca45c10f553901a2460e85028d /lib/Travel/Status/DE
parent2f711c0724c85f526782545a5f4225ac996b4a5f (diff)
HAFAS: departure board: add station accessor
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index ca2968b..2d9ba87 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -659,6 +659,42 @@ sub similar_stops {
return;
}
+sub station {
+ my ($self) = @_;
+
+ if ( $self->{station_info} ) {
+ return $self->{station_info};
+ }
+
+ my @locL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] };
+
+ my %prefc_by_loc;
+
+ for my $i ( 0 .. $#locL ) {
+ my $loc = $locL[$i];
+ if ( $loc->{pRefL} ) {
+ $prefc_by_loc{$i} = $#{ $loc->{pRefL} };
+ }
+ }
+
+ my @prefcounts = sort { $b->[0] <=> $a->[0] }
+ map { [ $_, $prefc_by_loc{$_} ] } keys %prefc_by_loc;
+
+ my $loc = $locL[ $prefcounts[0][0] ];
+
+ if ($loc) {
+ $self->{station_info} = {
+ name => $loc->{name},
+ uic => $loc->{extId},
+ };
+ }
+ else {
+ $self->{station_info} = {};
+ }
+
+ return $self->{station_info};
+}
+
sub messages {
my ($self) = @_;
return @{ $self->{messages} };