summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-10-10 15:50:33 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-10-10 15:50:33 +0200
commitadfbeff051c7384bfbce37e60efc7ee785203be5 (patch)
tree1324154697d223e000a75a2250947b6a23d684fc
parent70d7348525e60b23d3001245cb99c10b81bf3955 (diff)
Result: Fix type and line_no accessors ({train} does not always have a separating whitespace)
-rw-r--r--lib/Travel/Status/DE/HAFAS/Result.pm18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Result.pm b/lib/Travel/Status/DE/HAFAS/Result.pm
index dd69e14..d5b65ed 100644
--- a/lib/Travel/Status/DE/HAFAS/Result.pm
+++ b/lib/Travel/Status/DE/HAFAS/Result.pm
@@ -102,18 +102,30 @@ sub TO_JSON {
sub type {
my ($self) = @_;
+ my $type;
# $self->{train} is either "TYPE 12345" or "TYPE12345"
- my ($type) = ( $self->{train} =~ m{ ^ ([^[:space:]]+) }x );
+ if ( $self->{train} =~ m{ \s }x ) {
+ ($type) = ( $self->{train} =~ m{ ^ ([^[:space:]]+) }x );
+ }
+ else {
+ ($type) = ( $self->{train} =~ m{ ^ ([[:alpha:]]+) }x );
+ }
return $type;
}
sub line_no {
my ($self) = @_;
+ my $line_no;
# $self->{train} is either "TYPE 12345" or "TYPE12345"
- my ($line_no) = ( $self->{train} =~ m{ ([^[:space:]]+) $ }x );
+ if ( $self->{train} =~ m{ \s }x ) {
+ ($line_no) = ( $self->{train} =~ m{ ([^[:space:]]+) $ }x );
+ }
+ else {
+ ($line_no) = ( $self->{train} =~ m{ ([[:digit:]]+) $ }x );
+ }
return $line_no;
}
@@ -215,6 +227,8 @@ May contain extraneous whitespace characters.
Returns the line/train number, for instance "SB16" (bus line SB16),
"11" (Underground train line U 11) or 1011 ("RegionalExpress train 1011").
+Note that this may not be a number at all: Some transport services also
+use single-letter characters or words (e.g. "AIR") as line numbers.
=item $result->platform