diff options
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS.pm | 8 | ||||
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm index 66790b2..6221622 100644 --- a/lib/Travel/Status/DE/DBRIS.pm +++ b/lib/Travel/Status/DE/DBRIS.pm @@ -95,6 +95,11 @@ sub new { time_zone => 'Europe/Berlin', ); + $self->{strpdate_obj} //= DateTime::Format::Strptime->new( + pattern => '%Y-%m-%d', + time_zone => 'Europe/Berlin', + ); + my $json = $self->{json} = JSON->new->utf8; if ( $conf{async} ) { @@ -272,7 +277,8 @@ sub parse_journey { $self->{result} = Travel::Status::DE::DBRIS::Journey->new( json => $self->{raw_json}, - strptime_obj => $self->{strptime_obj} + strpdate_obj => $self->{strpdate_obj}, + strptime_obj => $self->{strptime_obj}, ); } diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm index c4f7df6..4900809 100644 --- a/lib/Travel/Status/DE/DBRIS/Journey.pm +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -10,15 +10,17 @@ use Travel::Status::DE::DBRIS::Location; our $VERSION = '0.01'; -Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(train is_cancelled)); +Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(day train is_cancelled)); sub new { my ( $obj, %opt ) = @_; my $json = $opt{json}; + my $strpdate = $opt{strpdate_obj}; my $strptime = $opt{strptime_obj}; my $ref = { + day => $strpdate->parse_datetime( $json->{reisetag} ), train => $json->{zugName}, is_cancelled => $json->{cancelled}, raw_route => $json->{halte}, @@ -31,6 +33,10 @@ sub new { push( @{ $ref->{messages} }, $message ); } + for my $attr ( @{ $json->{zugattribute} // [] } ) { + push( @{ $ref->{attributes} }, $attr ); + } + return $ref; } @@ -53,6 +59,12 @@ sub route { return @{ $self->{route} }; } +sub attributes { + my ($self) = @_; + + return @{ $self->{attributes} // [] }; +} + sub messages { my ($self) = @_; |