summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/EFA/Result.pm
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/DE/EFA/Result.pm
parent6ddf48b7f40ef7ad601c2fac579dc0a9dbad0bf1 (diff)
add route_interesting (only useful when full_routes is specified)
Diffstat (limited to 'lib/Travel/Status/DE/EFA/Result.pm')
-rw-r--r--lib/Travel/Status/DE/EFA/Result.pm50
1 files changed, 50 insertions, 0 deletions
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) = @_;