diff options
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS/Journey.pm')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm new file mode 100644 index 0000000..df7eada --- /dev/null +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -0,0 +1,69 @@ +package Travel::Status::DE::DBRIS::Journey; + +use strict; +use warnings; +use 5.020; + +use parent 'Class::Accessor'; + +our $VERSION = '0.01'; + +Travel::Status::DE::DBRIS::Journey->mk_ro_accessors( + qw(type dep sched_dep rt_dep is_cancelled line stop_name stop_eva id admin_id journey_id sched_platform platform dest_name dest_eva route) +); + +sub new { + my ( $obj, %opt ) = @_; + + my $json = $opt{json}->[0]; + my $strptime = $opt{strptime_obj}; + + my $ref = { + type => $json->{type}, + line => $json->{lineName}, + is_cancelled => $json->{canceled}, + dest_name => $json->{destination}{name}, + platform => $json->{platform}, + sched_platform => $json->{platformSchedule}, + dest_eva => $json->{destination}{evaNumber}, + raw_route => $json->{viaStops}, + raw_cancelled_route => $json->{canceledStopsAfterActualDestination}, + }; + + bless( $ref, $obj ); + + if ( $json->{timeSchedule} ) { + $ref->{sched_dep} = $strptime->parse_datetime( $json->{timeSchedule} ); + } + if ( $json->{timeDelayed} ) { + $ref->{rt_dep} = $strptime->parse_datetime( $json->{timeDelayed} ); + } + $ref->{dep} = $ref->{rt_dep} // $ref->{schd_dep}; + + return $ref; +} + +sub route { + my ($self) = @_; + + if ( $self->{route} ) { + return @{ $self->{route} }; + } + + @{ $self->{route} } + = map { Travel::Status::DE::DBRIS::Location->new( json => $_ ) } + ( @{ $self->{raw_route} // [] }, + @{ $self->{raw_cancelled_route} // [] } ); + + return @{ $self->{route} }; +} + +sub TO_JSON { + my ($self) = @_; + + my $ret = { %{$self} }; + + return $ret; +} + +1; |