summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-12-11 23:13:38 +0100
committerDaniel Friesel <derf@finalrewind.org>2013-12-11 23:13:38 +0100
commit0736de7268d9ac8d5edef06cb8838e19d9bfa667 (patch)
treebdc26a20c4a8b8e5f6bd622d4f715d919f5d55fb /lib/Travel
parent385eab07bef28d42e55bcab757f18864124523ab (diff)
Add -v/--via filter
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/ASEAG.pm31
1 files changed, 26 insertions, 5 deletions
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<name>.
+=item B<via> => I<vianame>
+
+Only return departures containing I<vianame> in their route. If B<stop> is set,
+I<vianame> must be in the route after the stop I<name>. If, in addition to
+that, B<full_routes> is set to B<before>, I<vianame> must be in the route
+before the stop I<name>. Respects B<fuzzy>. Implies C<< full_routes> => 'after' >> unless
+B<full_routes> is explicitly set to B<before> / B<after> / 1.
+
=back
=back