summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-01-03 21:01:14 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-01-03 21:01:14 +0100
commita292fc5ba4a8be919f2fc467cf528b79a6f8c7a3 (patch)
tree6303f4d15c4bed9a19671604f1b17bec6cc09315
parent6436acb5833ecec7f6bddc33461efb8c875d19b5 (diff)
add origin/destination accessors, support wings in orig/dest/train no
-rwxr-xr-xbin/db-wagenreihung10
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm61
2 files changed, 68 insertions, 3 deletions
diff --git a/bin/db-wagenreihung b/bin/db-wagenreihung
index 11572a9..8884547 100755
--- a/bin/db-wagenreihung
+++ b/bin/db-wagenreihung
@@ -71,9 +71,13 @@ my $wr = Travel::Status::DE::DBWagenreihung->new(
);
printf(
- "%s %s (%s) in %s Gleis %s\n\n",
- $wr->train_type, $wr->train_no, $wr->train_subtype // '-',
- $wr->station_name, $wr->platform
+ "%s: %s → %s (%s)\n%s Gleis %s\n\n",
+ join( ' / ', map { $wr->train_type . ' ' . $_ } $wr->train_numbers ),
+ join( ' / ', $wr->origins ),
+ join( ' / ', $wr->destinations ),
+ $wr->train_subtype // 'IC?',
+ $wr->station_name,
+ $wr->platform
);
for my $section ( $wr->sections ) {
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) = @_;