summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-12-11 18:27:22 +0100
committerDaniel Friesel <derf@finalrewind.org>2013-12-11 18:27:22 +0100
commitb8c4107c0096a8d6db88cfe69dcc2c9f1530e07f (patch)
treecb4e1e6f28151a1940e69cfd8bef5bbd553e5083
parentb5d492e649d266ae78ceb1bd7d04d22fc79a9ef9 (diff)
allow stop / full_route parameter to be set in ->results
-rwxr-xr-xbin/aseag-m16
-rw-r--r--lib/Travel/Status/DE/ASEAG.pm21
2 files changed, 22 insertions, 15 deletions
diff --git a/bin/aseag-m b/bin/aseag-m
index 1fb593f..5c2c453 100755
--- a/bin/aseag-m
+++ b/bin/aseag-m
@@ -33,15 +33,13 @@ if ( @ARGV != 1 ) {
my ($stop_name) = @ARGV;
-my $status = Travel::Status::DE::ASEAG->new(
- name => $stop_name,
- full_routes => $show_full_route
-);
+my $status = Travel::Status::DE::ASEAG->new;
sub show_help {
my ($code) = @_;
- print "Usage: aseag-m <stop name>\n" . "See also: man aseag-m\n";
+ print "Usage: B<aseag-m> [ B<-l> I<lines> ] [B<-f>] I< <stop name>\n"
+ . "See also: man aseag-m\n";
exit $code;
}
@@ -83,7 +81,13 @@ sub display_result {
sub show_results {
my @output;
- for my $d ( $status->results ) {
+ for my $d (
+ $status->results(
+ stop => $stop_name,
+ full_routes => $show_full_route
+ )
+ )
+ {
my $dtime = $d->time;
diff --git a/lib/Travel/Status/DE/ASEAG.pm b/lib/Travel/Status/DE/ASEAG.pm
index 488959e..3477231 100644
--- a/lib/Travel/Status/DE/ASEAG.pm
+++ b/lib/Travel/Status/DE/ASEAG.pm
@@ -22,7 +22,7 @@ sub new {
my $self = {
full_routes => $opt{full_routes} // 0,
fuzzy => $opt{fuzzy} // 1,
- stop => $opt{name},
+ stop => $opt{stop},
post => {
ReturnList =>
'lineid,linename,directionid,destinationtext,vehicleid,'
@@ -57,7 +57,7 @@ sub new {
return $self;
}
-sub new_from_xml {
+sub new_from_raw {
my ( $class, %opt ) = @_;
my $self = { raw_str => $opt{raw_str}, };
@@ -101,10 +101,9 @@ sub sprintf_time {
}
sub is_my_stop {
- my ( $self, $stop ) = @_;
- my $my_stop = $self->{stop};
+ my ( $self, $stop, $my_stop, $fuzzy ) = @_;
- if ( $self->{fuzzy} ) {
+ if ($fuzzy) {
return ( $stop =~ m{ $my_stop }ix ? 1 : 0 );
}
else {
@@ -113,9 +112,13 @@ sub is_my_stop {
}
sub results {
- my ($self) = @_;
+ my ( $self, %opt ) = @_;
my @results;
+ my $full_routes = $opt{full_routes} // $self->{full_routes} // 0;
+ my $fuzzy = $opt{fuzzy} // $self->{fuzzy} // 1;
+ my $stop = $opt{stop} // $self->{stop};
+
my $dt_now = DateTime->now( time_zone => 'Europe/Berlin' );
for my $dep ( @{ $self->{raw_list} } ) {
@@ -126,7 +129,7 @@ sub results {
) = @{$dep};
my @route;
- if ( $self->{stop} and not $self->is_my_stop($stopname) ) {
+ if ( $stop and not $self->is_my_stop( $stopname, $stop, $fuzzy ) ) {
next;
}
@@ -135,7 +138,7 @@ sub results {
next;
}
- if ( $self->{full_routes} ) {
+ if ($full_routes) {
@route = map { [ $_->[9] / 1000, $_->[1] ] }
grep { $_->[8] == $tripid } @{ $self->{raw_list} };
@@ -199,7 +202,7 @@ Travel::Status::DE::ASEAG - unofficial ASEAG departure monitor
use Travel::Status::DE::ASEAG;
my $status = Travel::Status::DE::ASEAG->new(
- name => 'Aachen Bushof'
+ stop => 'Aachen Bushof'
);
for my $d ($status->results) {