From 91a31f674b366d4e86a6bfae12c0922c396a7df1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 13 Jul 2011 14:13:15 +0200 Subject: DeutscheBahn/Result: Add delay accessor, remove info_raw --- Changelog | 2 +- bin/db-ris | 4 +--- lib/Travel/Status/DE/DeutscheBahn/Result.pm | 27 ++++++++++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Changelog b/Changelog index f390f9f..b9c5ed7 100644 --- a/Changelog +++ b/Changelog @@ -3,8 +3,8 @@ git HEAD [Travel::Status::DE::DeutscheBahn::Result] * The info accessor now strips the mostly useless "k.A." / "pünktlich" (train on time) text parts - * Use the new info_raw accessor to get the old info results * Add (slightly experimental) route_interesting accessor + * Add delay accessor Travel::Status::DE::DeutscheBahn 0.03 - Wed Jul 13 2011 diff --git a/bin/db-ris b/bin/db-ris index d787073..25842a0 100755 --- a/bin/db-ris +++ b/bin/db-ris @@ -88,15 +88,13 @@ for my $d ( $status->results() ) { my @via; - my $re_late = qr{ (?: ^ | , ) ca[.] \s \d+ \s Minuten \s sp.ter}ox; - @via = $d->route; if ( $filter_via and not( first { $_ =~ m{$filter_via}io } @via ) ) { next; } - if ( $ignore_late and $d->info =~ $re_late ) { + if ( $ignore_late and $d->delay ) { next; } diff --git a/lib/Travel/Status/DE/DeutscheBahn/Result.pm b/lib/Travel/Status/DE/DeutscheBahn/Result.pm index 5c2e9e1..79cf5d4 100644 --- a/lib/Travel/Status/DE/DeutscheBahn/Result.pm +++ b/lib/Travel/Status/DE/DeutscheBahn/Result.pm @@ -38,6 +38,21 @@ sub info { return $info; } +sub delay { + my ($self) = @_; + + my $info = $self->info_raw; + + if ( $info =~ m{ p.nktlich }ox ) { + return 0; + } + if ( $info =~ m{ ca[.] \s (? \d+ ) \s Minuten \s sp.ter }ox ) { + return $+{delay}; + } + + return; +} + sub origin { my ($self) = @_; @@ -156,16 +171,14 @@ either the train's destination or its origin station. Convenience aliases for $result->route_end. -=item $result->info +=item $result->delay -Returns additional information, for instance in case the train is delayed. May -be an empty string if no (useful) information is available. +Returns the train's delay in steps of 5 minutes, or undef if it is unknown. -=item $result->info_raw +=item $result->info -Returns the raw info string. B only tells you about delays, platform -changes and such, B also explicitly states wether a train is on time -or no information is available. +Returns additional information, for instance the reason why the train is +delayed. May be an empty string if no (useful) information is available. =item $result->platform -- cgit v1.2.3