diff options
Diffstat (limited to 'lib/Travel/Status/DE/EFA.pm')
-rw-r--r-- | lib/Travel/Status/DE/EFA.pm | 132 |
1 files changed, 8 insertions, 124 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index 8591bc1..6404d89 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -423,129 +423,6 @@ sub parse_line { ); } -sub parse_route { - my ( $self, $stop_seq, $requested_id ) = @_; - my @ret; - - if ( not $stop_seq ) { - return \@ret; - } - - # Oh EFA, you so silly - if ( ref($stop_seq) eq 'HASH' ) { - - # For lines that start or terminate at the requested stop, onwardStopSeq / prevStopSeq includes the requested stop. - if ( $stop_seq->{ref}{id} eq $requested_id ) { - return \@ret; - } - $stop_seq = [$stop_seq]; - } - - for my $stop ( @{ $stop_seq // [] } ) { - my $ref = $stop->{ref}; - my ( $arr, $dep ); - - if ( $ref->{arrDateTimeSec} ) { - $arr = $self->{strp_stopseq_s} - ->parse_datetime( $ref->{arrDateTimeSec} ); - } - elsif ( $ref->{arrDateTime} ) { - $arr = $self->{strp_stopseq}->parse_datetime( $ref->{arrDateTime} ); - } - - if ( $ref->{depDateTimeSec} ) { - $dep = $self->{strp_stopseq_s} - ->parse_datetime( $ref->{depDateTimeSec} ); - } - elsif ( $ref->{depDateTime} ) { - $dep = $self->{strp_stopseq}->parse_datetime( $ref->{depDateTime} ); - } - - push( - @ret, - Travel::Status::DE::EFA::Stop->new( - arr => $arr, - dep => $dep, - id => $stop->{ref}{id}, - full_name => $stop->{name}, - place => $stop->{place}, - name => $stop->{nameWO}, - platform => $ref->{platform} || $stop->{platformName} || undef, - ) - ); - } - - return \@ret; -} - -sub parse_departure { - my ( $self, $departure ) = @_; - - my ( $sched_dt, $real_dt ); - my ( $prev_route, $next_route ); - - if ( my $dt = $departure->{dateTime} ) { - $sched_dt = DateTime->new( - year => $dt->{year}, - month => $dt->{month}, - day => $dt->{day}, - hour => $dt->{hour}, - minute => $dt->{minute}, - second => $dt->{second} // 0, - time_zone => 'Europe/Berlin', - ); - } - - if ( my $dt = $departure->{realDateTime} ) { - $real_dt = DateTime->new( - year => $dt->{year}, - month => $dt->{month}, - day => $dt->{day}, - hour => $dt->{hour}, - minute => $dt->{minute}, - second => $dt->{second} // 0, - time_zone => 'Europe/Berlin', - ); - } - - if ( $departure->{prevStopSeq} ) { - $prev_route = $self->parse_route( $departure->{prevStopSeq}, - $departure->{stopID} ); - } - if ( $departure->{onwardStopSeq} ) { - $next_route = $self->parse_route( $departure->{onwardStopSeq}, - $departure->{stopID} ); - } - - my @hints - = map { $_->{content} } @{ $departure->{servingLine}{hints} // [] }; - - return Travel::Status::DE::EFA::Departure->new( - rt_datetime => $real_dt, - platform => $departure->{platform}, - platform_name => $departure->{platformName}, - platform_type => $departure->{pointType}, - key => $departure->{servingLine}{key}, - stateless => $departure->{servingLine}{stateless}, - stop_id => $departure->{stopID}, - line => $departure->{servingLine}{symbol}, - train_type => $departure->{servingLine}{trainType}, - train_name => $departure->{servingLine}{trainName}, - train_no => $departure->{servingLine}{trainNum}, - origin => $departure->{servingLine}{directionFrom}, - destination => $departure->{servingLine}{direction}, - occupancy => $departure->{occupancy}, - countdown => $departure->{countdown}, - delay => $departure->{servingLine}{delay}, - sched_datetime => $sched_dt, - type => $departure->{servingLine}{name}, - mot => $departure->{servingLine}{motType}, - hints => \@hints, - prev_route => $prev_route, - next_route => $next_route, - ); -} - sub results { my ($self) = @_; my @results; @@ -557,7 +434,14 @@ sub results { my $json = $self->{response}; for my $departure ( @{ $json->{departureList} // [] } ) { - push( @results, $self->parse_departure($departure) ); + push( + @results, + Travel::Status::DE::EFA::Departure->new( + json => $departure, + strp_stopseq => $self->{strp_stopseq}, + strp_stopseq_s => $self->{strp_stopseq_s} + ) + ); } @results = map { $_->[0] } |