summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-01-14 18:38:17 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-01-14 18:38:17 +0100
commit502bdd149da8c972713984151e4b64449577eae4 (patch)
treeeb1716b644b6b0d3da33ac0f5cef911a257127e4
parent894267671c2a06d77bfcd5fbb53994282f74dcde (diff)
Turn add_ar / add_dp into setters as well
This is a preparation for a future refresh_realtime function which only updates the realtime (fchg) part of all departures.
-rw-r--r--lib/Travel/Status/DE/IRIS.pm4
-rw-r--r--lib/Travel/Status/DE/IRIS/Result.pm34
2 files changed, 34 insertions, 4 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index a063c5e..9b5b46d 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -256,7 +256,7 @@ sub get_realtime {
);
}
if ($e_ar) {
- $result->add_ar(
+ $result->set_ar(
arrival_ts => $e_ar->getAttribute('ct'),
plan_arrivaL_ts => $e_ar->getAttribute('pt'),
platform => $e_ar->getAttribute('cp'),
@@ -267,7 +267,7 @@ sub get_realtime {
);
}
if ($e_dp) {
- $result->add_dp(
+ $result->set_dp(
departure_ts => $e_dp->getAttribute('ct'),
plan_departure_ts => $e_dp->getAttribute('pt'),
platform => $e_dp->getAttribute('cp'),
diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm
index 5b06555..f9fdabc 100644
--- a/lib/Travel/Status/DE/IRIS/Result.pm
+++ b/lib/Travel/Status/DE/IRIS/Result.pm
@@ -94,7 +94,7 @@ sub new {
return bless( $ref, $obj );
}
-sub add_ar {
+sub set_ar {
my ( $self, %attrib ) = @_;
my $strp = DateTime::Format::Strptime->new(
@@ -115,16 +115,28 @@ sub add_ar {
= $self->arrival->subtract_datetime( $self->sched_arrival )
->in_units('minutes');
}
+ else {
+ $self->{arrival} = $self->{sched_arrival};
+ $self->{delay} = 0;
+ }
if ( $attrib{platform} ) {
$self->{platform} = $attrib{platform};
}
+ else {
+ $self->{platform} = $self->{sched_platform};
+ }
if ( $attrib{route_pre} ) {
$self->{route_pre} = [ split( qr{[|]}, $attrib{route_pre} // q{} ) ];
$self->{route_start} = $self->{route_pre}[0];
}
+ else {
+ $self->{route_pre} = $self->{sched_route_pre};
+ $self->{route_start} = $self->{sched_route_start};
+ }
+ # also only for unscheduled arrivals
if ( $attrib{sched_route_pre} ) {
$self->{sched_route_pre}
= [ split( qr{[|]}, $attrib{sched_route_pre} // q{} ) ];
@@ -134,11 +146,14 @@ sub add_ar {
if ( $attrib{status} and $attrib{status} eq 'c' ) {
$self->{is_cancelled} = 1;
}
+ else {
+ $self->{is_cancelled} = 0;
+ }
return $self;
}
-sub add_dp {
+sub set_dp {
my ( $self, %attrib ) = @_;
my $strp = DateTime::Format::Strptime->new(
@@ -159,16 +174,28 @@ sub add_dp {
= $self->departure->subtract_datetime( $self->sched_departure )
->in_units('minutes');
}
+ else {
+ $self->{departure} = $self->{sched_departure};
+ $self->{delay} = 0;
+ }
if ( $attrib{platform} ) {
$self->{platform} = $attrib{platform};
}
+ else {
+ $self->{platform} = $self->{sched_platform};
+ }
if ( $attrib{route_post} ) {
$self->{route_post} = [ split( qr{[|]}, $attrib{route_post} // q{} ) ];
$self->{route_end} = $self->{route_post}[-1];
}
+ else {
+ $self->{route_post} = $self->{sched_route_post};
+ $self->{route_end} = $self->{sched_route_end};
+ }
+ # also only for unscheduled departures
if ( $attrib{sched_route_post} ) {
$self->{sched_route_post}
= [ split( qr{[|]}, $attrib{sched_route_post} // q{} ) ];
@@ -178,6 +205,9 @@ sub add_dp {
if ( $attrib{status} and $attrib{status} eq 'c' ) {
$self->{is_cancelled} = 1;
}
+ else {
+ $self->{is_cancelled} = 0;
+ }
return $self;
}