summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-19 19:55:37 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-19 20:31:25 +0100
commit523817239799733c15b900506ad57c5fc87c29de (patch)
tree8aa75cbeba4d828d2d5ccc99f6fc96d598d0ebbf
parentc95333993e11598c36411bf432e5508d7e6fa1b7 (diff)
sanitize platform number, add platform_db accessor
-rwxr-xr-xbin/efa-m10
-rw-r--r--lib/Travel/Status/DE/VRR.pm7
-rw-r--r--lib/Travel/Status/DE/VRR/Result.pm2
-rw-r--r--t/20-vrr.t9
4 files changed, 22 insertions, 6 deletions
diff --git a/bin/efa-m b/bin/efa-m
index a6b8bec..66694c6 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -105,17 +105,23 @@ if ( my $err = $status->errstr ) {
for my $d ( $status->results ) {
+ my $platform = $d->platform;
+
+ if ( $d->platform_db ) {
+ $platform .= ' (DB)';
+ }
+
if (
( @grep_lines and not( $d->line ~~ \@grep_lines ) )
or ( @grep_platforms
- and not( substr( $d->platform, 6 ) ~~ \@grep_platforms ) )
+ and not( $platform ~~ \@grep_platforms ) )
)
{
next;
}
push( @output,
- [ $d->time, $d->platform, $d->line, $d->destination, $d->info ] );
+ [ $d->time, $platform, $d->line, $d->destination, $d->info ] );
}
display_result(@output);
diff --git a/lib/Travel/Status/DE/VRR.pm b/lib/Travel/Status/DE/VRR.pm
index f976c1e..065d56c 100644
--- a/lib/Travel/Status/DE/VRR.pm
+++ b/lib/Travel/Status/DE/VRR.pm
@@ -187,12 +187,19 @@ sub results {
my $countdown = $e->getAttribute('countdown');
my $delay = $e_info->getAttribute('delay') // 0;
+ my $platform_is_db = 0;
+
+ if ( $platform =~ s{ ^ \# }{}ox ) {
+ $platform_is_db = 1;
+ }
+
push(
@results,
Travel::Status::DE::VRR::Result->new(
date => $rdate,
time => $rtime,
platform => $platform,
+ platform_db => $platform_is_db,
line => $line,
destination => decode( 'UTF-8', $dest ),
countdown => $countdown,
diff --git a/lib/Travel/Status/DE/VRR/Result.pm b/lib/Travel/Status/DE/VRR/Result.pm
index 93e651f..9fdd826 100644
--- a/lib/Travel/Status/DE/VRR/Result.pm
+++ b/lib/Travel/Status/DE/VRR/Result.pm
@@ -9,7 +9,7 @@ use parent 'Class::Accessor';
our $VERSION = '0.02';
Travel::Status::DE::VRR::Result->mk_ro_accessors(
- qw(countdown date delay destination info line platform sched_date sched_time time type)
+ qw(countdown date delay destination info line platform platform_db sched_date sched_time time type)
);
sub new {
diff --git a/t/20-vrr.t b/t/20-vrr.t
index 1789e4d..9dccad4 100644
--- a/t/20-vrr.t
+++ b/t/20-vrr.t
@@ -6,7 +6,7 @@ use utf8;
use Encode qw(decode);
use File::Slurp qw(slurp);
-use Test::More tests => 111;
+use Test::More tests => 114;
BEGIN {
use_ok('Travel::Status::DE::VRR');
@@ -35,7 +35,8 @@ is($results[0]->time, '09:40', 'first result: real time ok');
is($results[0]->delay, 4, 'first result: delay 4');
is($results[0]->sched_date, '16.11.2011', 'first result: scheduled date ok');
is($results[0]->sched_time, '09:36', 'first result: scheduled time ok');
-is($results[0]->platform, '#1', 'first result: platform ok');
+is($results[0]->platform, '1', 'first result: platform ok');
+is($results[0]->platform_db, 1, 'first result: platform_db ok');
is($results[3]->destination, decode('UTF-8', 'Mülheim Heißen Kirche'), 'fourth result: destination ok');
is($results[3]->info, decode('UTF-8', 'Ab (H) Heißen Kirche, Umstieg in den SEV Ri. Mülheim Hbf.'), 'fourth result: no info');
@@ -46,6 +47,7 @@ is($results[3]->delay, 0, 'fourth result: delay 0');
is($results[3]->sched_date, '16.11.2011', 'fourth result: scheduled date ok');
is($results[3]->sched_time, '09:39', 'fourth result: scheduled time ok');
is($results[3]->platform, '2', 'fourth result: platform ok');
+is($results[3]->platform_db, 0, 'fourth result: platform_db ok');
is($results[-1]->destination, 'Hamm (Westf)', 'last result: destination ok');
is($results[-1]->info, decode('UTF-8', 'Fahrradmitnahme begrenzt möglich'), 'last result: info ok');
@@ -55,4 +57,5 @@ is($results[-1]->date, '16.11.2011', 'last result: date ok');
is($results[-1]->time, '10:05', 'last result: time ok');
is($results[-1]->sched_date, '16.11.2011', 'first result: scheduled date ok');
is($results[-1]->sched_time, '09:53', 'first result: scheduled time ok');
-is($results[-1]->platform, '#6', 'last result: platform ok');
+is($results[-1]->platform, '6', 'last result: platform ok');
+is($results[-1]->platform_db, 1, 'last result: platform ok');