summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBWagenreihung.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-12-26 19:03:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-12-26 19:03:58 +0100
commit789709229f032afe6ba0b4baac00fc978d737c92 (patch)
tree368922cc8ef1a73d37bf8704605daa7032f99aa9 /lib/Travel/Status/DE/DBWagenreihung.pm
parent8a0f122a427aab5b0c505ffb2252d05176767c55 (diff)
Fix direction
Diffstat (limited to 'lib/Travel/Status/DE/DBWagenreihung.pm')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index 5308961..0a750b5 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -89,18 +89,7 @@ sub error {
sub direction {
my ($self) = @_;
- my @wagons = $self->wagons;
-
- if ( not @wagons ) {
- return undef;
- }
-
- if ( $wagons[0]->{position}{start_percent}
- > $wagons[-1]{position}{start_percent} )
- {
- return 0;
- }
- return 100;
+ return $self->{direction};
}
sub sections {
@@ -142,6 +131,16 @@ sub wagons {
);
}
}
+ if ( @{ $self->{wagons} } > 1 ) {
+ if ( $self->{wagons}[0]->{position}{start_percent}
+ > $self->{wagons}[-1]->{position}{start_percent} )
+ {
+ $self->{direction} = 100;
+ }
+ else {
+ $self->{direction} = 0;
+ }
+ }
@{ $self->{wagons} } = sort {
$a->{position}->{start_percent} <=> $b->{position}->{start_percent}
} @{ $self->{wagons} };