diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-12-24 10:01:08 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-12-24 10:01:08 +0100 |
commit | 9cb71f78d09b8dc6e7b431c31c2cfac7657d7682 (patch) | |
tree | 53531d309d9e5e71fa4d5a12d9fccbb6a7784331 /lib/Travel/Status/DE/DBRIS/Journey.pm | |
parent | e1535415b0ee257b0a475e7de5978612e6153ec3 (diff) |
add journey support
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS/Journey.pm')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm index 47dd726..c4f7df6 100644 --- a/lib/Travel/Status/DE/DBRIS/Journey.pm +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -6,11 +6,11 @@ use 5.020; use parent 'Class::Accessor'; +use Travel::Status::DE::DBRIS::Location; + our $VERSION = '0.01'; -Travel::Status::DE::DBRIS::Journey->mk_ro_accessors( - qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva id platform rt_platform destination via via_last) -); +Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(train is_cancelled)); sub new { my ( $obj, %opt ) = @_; @@ -19,36 +19,15 @@ sub new { my $strptime = $opt{strptime_obj}; my $ref = { - type => $json->{verkehrmittel}{kurzText}, - line => $json->{verkehrmittel}{mittelText}, - id => $json->{journeyId}, - stop_eva => $json->{bahnhofsId}, - destination => $json->{terminus}, - platform => $json->{gleis}, - rt_platform => $json->{ezGleis}, - via => $json->{ueber}, - via_last => ( $json->{ueber} // [] )->[-1], + train => $json->{zugName}, + is_cancelled => $json->{cancelled}, + raw_route => $json->{halte}, + strptime_obj => $strptime, }; bless( $ref, $obj ); - if ( $json->{zeit} ) { - $ref->{sched_dep} = $strptime->parse_datetime( $json->{zeit} ); - } - if ( $json->{ezZeit} ) { - $ref->{rt_dep} = $strptime->parse_datetime( $json->{ezZeit} ); - } - $ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep}; - - if ( $ref->{sched_dep} and $ref->{rt_dep} ) { - $ref->{delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} ) - ->in_units('minutes'); - } - - for my $message ( @{ $json->{meldungen} // [] } ) { - if ( $message->{type} and $message->{type} eq 'HALT_AUSFALL' ) { - $ref->{is_cancelled} = 1; - } + for my $message ( @{ $json->{himMeldungen} // [] } ) { push( @{ $ref->{messages} }, $message ); } @@ -63,8 +42,12 @@ sub route { } @{ $self->{route} } - = map { Travel::Status::DE::DBRIS::Location->new( json => $_ ) } - ( @{ $self->{raw_route} // [] }, + = map { + Travel::Status::DE::DBRIS::Location->new( + json => $_, + strptime_obj => $self->{strptime_obj} + ) + } ( @{ $self->{raw_route} // [] }, @{ $self->{raw_cancelled_route} // [] } ); return @{ $self->{route} }; |