summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-06-04 18:18:18 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-06-04 18:18:18 +0200
commitc56337cef1d3a4069fae48c1d90953f5194556e0 (patch)
tree3f44794b1c64ae66ae88047f60507c7e0b434e2a /lib/Travel/Status
parent6ddf48b7f40ef7ad601c2fac579dc0a9dbad0bf1 (diff)
add route_interesting (only useful when full_routes is specified)
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/EFA.pm5
-rw-r--r--lib/Travel/Status/DE/EFA/Result.pm50
2 files changed, 53 insertions, 2 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index 06ff1c2..c134698 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -162,7 +162,7 @@ sub errstr {
sub sprintf_date {
my ($e) = @_;
- if ($e->getAttribute('day') == -1) {
+ if ( $e->getAttribute('day') == -1 ) {
return undef;
}
@@ -176,7 +176,7 @@ sub sprintf_date {
sub sprintf_time {
my ($e) = @_;
- if ($e->getAttribute('minute') == -1) {
+ if ( $e->getAttribute('minute') == -1 ) {
return undef;
}
@@ -322,6 +322,7 @@ sub parse_route {
dep_date => sprintf_date( $dates[-1] ),
dep_time => sprintf_time( $times[-1] ),
stop => decode( 'UTF-8', $e->getAttribute('name') ),
+ stop_suf => decode( 'UTF-8', $e->getAttribute('nameWO') ),
platform => $e->getAttribute('platformName'),
}
);
diff --git a/lib/Travel/Status/DE/EFA/Result.pm b/lib/Travel/Status/DE/EFA/Result.pm
index f729034..e598ef8 100644
--- a/lib/Travel/Status/DE/EFA/Result.pm
+++ b/lib/Travel/Status/DE/EFA/Result.pm
@@ -4,6 +4,8 @@ use strict;
use warnings;
use 5.010;
+no if $] >= 5.018, warnings => 'experimental::smartmatch';
+
use parent 'Class::Accessor';
our $VERSION = '1.09';
@@ -41,6 +43,54 @@ sub route_post {
return @{ $self->{next_route} };
}
+sub route_interesting {
+ my ( $self, $max_parts ) = @_;
+
+ my @via = $self->route_post;
+ my ( @via_main, @via_show, $last_stop );
+ $max_parts //= 3;
+
+ for my $stop (@via) {
+ if ( $stop =~ m{ Bf | Hbf | Flughafen | S $ }ox ) {
+ push( @via_main, $stop );
+ }
+ }
+ $last_stop = pop(@via);
+
+ if ( @via_main and $via_main[-1] eq $last_stop ) {
+ pop(@via_main);
+ }
+ if ( @via and $via[-1] eq $last_stop ) {
+ pop(@via);
+ }
+
+ if ( @via_main and @via and $via[0] eq $via_main[0] ) {
+ shift(@via_main);
+ }
+
+ if ( @via < $max_parts ) {
+ @via_show = @via;
+ }
+ else {
+ if ( @via_main >= $max_parts ) {
+ @via_show = ( $via[0] );
+ }
+ else {
+ @via_show = splice( @via, 0, $max_parts - @via_main );
+ }
+
+ while ( @via_show < $max_parts and @via_main ) {
+ my $stop = shift(@via_main);
+ if ( $stop ~~ \@via_show or $stop eq $last_stop ) {
+ next;
+ }
+ push( @via_show, $stop );
+ }
+ }
+
+ return @via_show;
+}
+
sub TO_JSON {
my ($self) = @_;