From 0736de7268d9ac8d5edef06cb8838e19d9bfa667 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Dec 2013 23:13:38 +0100 Subject: Add -v/--via filter --- lib/Travel/Status/DE/ASEAG.pm | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'lib/Travel/Status') diff --git a/lib/Travel/Status/DE/ASEAG.pm b/lib/Travel/Status/DE/ASEAG.pm index 3a22652..ed17d98 100644 --- a/lib/Travel/Status/DE/ASEAG.pm +++ b/lib/Travel/Status/DE/ASEAG.pm @@ -11,8 +11,9 @@ our $VERSION = '0.00'; use Carp qw(confess cluck); use DateTime; use Encode qw(encode decode); -use Travel::Status::DE::ASEAG::Result; +use List::MoreUtils qw(none); use LWP::UserAgent; +use Travel::Status::DE::ASEAG::Result; sub new { my ( $class, %opt ) = @_; @@ -24,6 +25,7 @@ sub new { fuzzy => $opt{fuzzy} // 1, hide_past => $opt{hide_past} // 1, stop => $opt{stop}, + via => $opt{via}, post => { ReturnList => 'lineid,linename,directionid,destinationtext,vehicleid,' @@ -120,10 +122,15 @@ sub results { my $fuzzy = $opt{fuzzy} // $self->{fuzzy} // 1; my $hide_past = $opt{hide_past} // $self->{hide_past} // 1; my $stop = $opt{stop} // $self->{stop}; + my $via = $opt{via} // $self->{via}; my $dt_now = DateTime->now( time_zone => 'Europe/Berlin' ); my $ts_now = $dt_now->epoch; + if ($via) { + $full_routes ||= 'after'; + } + for my $dep ( @{ $self->{raw_list} } ) { my ( @@ -155,10 +162,6 @@ sub results { @route = map { [ $_->[9] / 1000, $_->[1] ] } grep { $_->[8] == $tripid } @{ $self->{raw_list} }; - if ($hide_past) { - @route = grep { $_->[0] >= $ts_now } @route; - } - if ( $full_routes eq 'before' ) { @route = grep { $_->[0] < $ts_dep } @route; } @@ -166,6 +169,16 @@ sub results { @route = grep { $_->[0] > $ts_dep } @route; } + if ( $via + and none { $self->is_my_stop( $_->[1], $via, $fuzzy ) } @route ) + { + next; + } + + if ($hide_past) { + @route = grep { $_->[0] >= $ts_now } @route; + } + @route = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, $_->[0] ] } @route; @@ -292,6 +305,14 @@ Do not include past departures in the result list and the computed timetables. Only return departures at stop I. +=item B => I + +Only return departures containing I in their route. If B is set, +I must be in the route after the stop I. If, in addition to +that, B is set to B, I must be in the route +before the stop I. Respects B. Implies C<< full_routes> => 'after' >> unless +B is explicitly set to B / B / 1. + =back =back -- cgit v1.2.3