summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-04-27 11:04:07 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-04-27 11:04:07 +0200
commit210149a9c387fc0ac5bbab796bf3928e816c3783 (patch)
tree71abdc1efed4d6f30e331b4a937a151b22d87fba
parent80139a3a3166ee8cd8bfbed4f67e1bdca03cfa81 (diff)
Refactor origins and destinations into common parse_wings function
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm54
1 files changed, 17 insertions, 37 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index dceaf2f..ae65f22 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -199,6 +199,8 @@ sub parse_wagonorder {
$self->{train_no} = $self->{data}{istformation}{zugnummer};
$self->parse_wagons;
+ $self->{origins} = $self->parse_wings('startbetriebsstellename');
+ $self->{destinations} = $self->parse_wings('zielbetriebsstellename');
}
sub errstr {
@@ -247,59 +249,37 @@ sub has_bad_wagons {
return $self->{has_bad_wagons} = 0;
}
-sub origins {
- my ($self) = @_;
+sub parse_wings {
+ my ( $self, $attr ) = @_;
- if ( exists $self->{origins} ) {
- return @{ $self->{origins} };
- }
-
- my @origins;
+ my @names;
my %section;
for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
- my $origin = $group->{startbetriebsstellename};
+ my $name = $group->{$attr};
my @sections = map { $_->{fahrzeugsektor} } @{ $group->{allFahrzeug} };
- push( @{ $section{$origin} }, @sections );
- push( @origins, $origin );
+ push( @{ $section{$name} }, @sections );
+ push( @names, $name );
}
- @origins = uniq @origins;
-
- @origins
- = map { { name => $_, sections => [ uniq @{ $section{$_} } ] } } @origins;
+ @names = uniq @names;
- $self->{origins} = \@origins;
+ @names
+ = map { { name => $_, sections => [ uniq @{ $section{$_} } ] } } @names;
- return @origins;
+ return \@names;
}
sub destinations {
my ($self) = @_;
- if ( exists $self->{destinations} ) {
- return @{ $self->{destinations} };
- }
-
- my @destinations;
- my %section;
-
- for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
- my $destination = $group->{zielbetriebsstellename};
- my @sections = map { $_->{fahrzeugsektor} } @{ $group->{allFahrzeug} };
- push( @{ $section{$destination} }, @sections );
- push( @destinations, $destination );
- }
-
- @destinations = uniq @destinations;
-
- @destinations
- = map { { name => $_, sections => [ uniq @{ $section{$_} } ] } }
- @destinations;
+ return @{ $self->{destinations} // [] };
+}
- $self->{destinations} = \@destinations;
+sub origins {
+ my ($self) = @_;
- return @destinations;
+ return @{ $self->{origins} // [] };
}
sub sections {