From a292fc5ba4a8be919f2fc467cf528b79a6f8c7a3 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 3 Jan 2019 21:01:14 +0100 Subject: add origin/destination accessors, support wings in orig/dest/train no --- lib/Travel/Status/DE/DBWagenreihung.pm | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'lib') diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm index 51253f9..2febe4d 100644 --- a/lib/Travel/Status/DE/DBWagenreihung.pm +++ b/lib/Travel/Status/DE/DBWagenreihung.pm @@ -8,6 +8,7 @@ our $VERSION = '0.00'; use Carp qw(cluck confess); use JSON; +use List::Util qw(uniq); use LWP::UserAgent; use Travel::Status::DE::DBWagenreihung::Section; use Travel::Status::DE::DBWagenreihung::Wagon; @@ -92,6 +93,46 @@ sub direction { return $self->{direction}; } +sub origins { + my ($self) = @_; + + if ( exists $self->{origins} ) { + return @{ $self->{origins} }; + } + + my @origins; + + for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) { + push( @origins, $group->{startbetriebsstellename} ); + } + + @origins = uniq @origins; + + $self->{origins} = \@origins; + + return @origins; +} + +sub destinations { + my ($self) = @_; + + if ( exists $self->{destinations} ) { + return @{ $self->{destinations} }; + } + + my @destinations; + + for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) { + push( @destinations, $group->{zielbetriebsstellename} ); + } + + @destinations = uniq @destinations; + + $self->{destinations} = \@destinations; + + return @destinations; +} + sub platform { my ($self) = @_; @@ -149,6 +190,26 @@ sub train_type { return $self->{data}{istformation}{zuggattung}; } +sub train_numbers { + my ($self) = @_; + + if ( exists $self->{train_numbers} ) { + return @{ $self->{train_numbers} }; + } + + my @numbers; + + for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) { + push( @numbers, $group->{verkehrlichezugnummer} ); + } + + @numbers = uniq @numbers; + + $self->{train_numbers} = \@numbers; + + return @numbers; +} + sub train_no { my ($self) = @_; -- cgit v1.2.3