From 10687196f1f39d01c17a415898758b3a65608396 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 13 Jul 2011 13:13:24 +0200 Subject: DeutscheBahn/Result: Return only useful text in info, add info_raw for the raw string --- lib/Travel/Status/DE/DeutscheBahn.pm | 5 +---- lib/Travel/Status/DE/DeutscheBahn/Result.pm | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index 8919dfc..9f71eb0 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -142,9 +142,6 @@ sub results { $str =~ s/ +$//; } - $info =~ s{ ,Grund }{}ox; - $info =~ s{ ^ \s+ }{}ox; - while ( $route =~ m{$re_via}g ) { if ($first) { $first = 0; @@ -168,7 +165,7 @@ sub results { route => \@via, route_end => $dest, platform => $platform, - info => $info, + info_raw => $info, ) ); } diff --git a/lib/Travel/Status/DE/DeutscheBahn/Result.pm b/lib/Travel/Status/DE/DeutscheBahn/Result.pm index 969658d..660abc5 100644 --- a/lib/Travel/Status/DE/DeutscheBahn/Result.pm +++ b/lib/Travel/Status/DE/DeutscheBahn/Result.pm @@ -9,7 +9,7 @@ use parent 'Class::Accessor'; our $VERSION = '0.03'; Travel::Status::DE::DeutscheBahn::Result->mk_ro_accessors( - qw(time train route_end route_raw platform info)); + qw(time train route_end route_raw platform info_raw)); sub new { my ( $obj, %conf ) = @_; @@ -25,6 +25,19 @@ sub destination { return $self->{route_end}; } +sub info { + my ($self) = @_; + + my $info = $self->info_raw; + + $info =~ s{ ,Grund }{}ox; + $info =~ s{ ^ \s+ }{}ox; + $info =~ s{ (?: ^ | , ) (?: p.nktlich | k [.] A [.] ) }{}ox; + $info =~ s{ ^ , }{}ox; + + return $info; +} + sub origin { my ($self) = @_; @@ -99,8 +112,14 @@ Convenience aliases for $result->route_end. =item $result->info -Returns additional information, usually wether the train is on time or -delayed. +Returns additional information, for instance in case the train is delayed. May +be an empty string if no (useful) information is available. + +=item $result->info_raw + +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. =item $result->platform -- cgit v1.2.3