summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-11 19:52:11 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-11 19:52:11 +0200
commitae8462fc983013bf27358a0d4a17cca73b8cb1e7 (patch)
tree0e8452a1b56b7758caeffdb0284cd95d809b96c6 /lib
parentde432ead84057a6f9234cbcb56004d625333a7bd (diff)
exclusive _and_ inclusive mots \o/
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm33
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 8cf03e3..3cdafb3 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -61,6 +61,7 @@ sub new {
my $ref = {
active_service => $service,
developer_mode => $conf{developer_mode},
+ exclusive_mots => $conf{exclusive_mots},
excluded_mots => $conf{excluded_mots},
post => {
input => $conf{station},
@@ -114,27 +115,43 @@ sub new {
sub set_productfilter {
my ($self) = @_;
- my $service = $self->{active_service};
+ my $service = $self->{active_service};
+ my $mot_default = '1';
if ( not $service or not exists $hafas_instance{$service}{productbits} ) {
return;
}
+ my %mot_pos;
+ for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) {
+ $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i;
+ }
+
+ if ( $self->{exclusive_mots} and @{ $self->{exclusive_mots} } ) {
+ $mot_default = '0';
+ }
+
$self->{post}{productsFilter}
- = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } );
+ = $mot_default x ( scalar @{ $hafas_instance{$service}{productbits} } );
- if ( $self->{excluded_mots} and @{ $self->{excluded_mots} } ) {
- my %mot_pos;
- for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) {
- $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i;
+ if ( $self->{exclusive_mots} and @{ $self->{exclusive_mots} } ) {
+ for my $mot ( @{ $self->{exclusive_mots} } ) {
+ if ( exists $mot_pos{$mot} ) {
+ substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1, '1' );
+ }
}
+ }
+
+ if ( $self->{excluded_mots} and @{ $self->{excluded_mots} } ) {
for my $mot ( @{ $self->{excluded_mots} } ) {
if ( exists $mot_pos{$mot} ) {
- substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1 ) = 0;
+ substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1, '0' );
}
}
}
+ say $self->{post}{productsFilter};
+
}
sub check_input_error {
@@ -198,7 +215,7 @@ sub results {
push( @messages, $n->getAttribute('header') );
}
- substr( $date, 6, 0 ) = '20';
+ substr( $date, 6, 0, '20' );
$info //= q{};
$routeinfo //= q{};