summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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) = @_;