From 99852d760a18a9d87acc832fd0557f630f5e69eb Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 30 Jan 2025 22:26:16 +0100 Subject: parse and expose messages --- lib/Travel/Routing/DE/DBRIS/Connection.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/Travel/Routing/DE') diff --git a/lib/Travel/Routing/DE/DBRIS/Connection.pm b/lib/Travel/Routing/DE/DBRIS/Connection.pm index 2ad46d8..d7c74f0 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection.pm @@ -94,6 +94,19 @@ sub new { $ref->{$key} = $ref->{segments}[-1]{$key}; } + for my $note ( @{ $json->{risNotizen} // [] } ) { + push( @{ $ref->{notes} }, $note ); + if ( $note->{key} eq 'text.realtime.connection.cancelled' ) { + $ref->{is_cancelled} = 1; + } + elsif ( $note->{key} eq 'text.realtime.connection.brokentrip' ) { + $ref->{is_unlikely} = 1; + } + } + for my $message ( @{ $json->{messages} // [] } ) { + push( @{ $ref->{messages} }, $message ); + } + bless( $ref, $obj ); return $ref; @@ -105,6 +118,18 @@ sub segments { return @{ $self->{segments} // [] }; } +sub notes { + my ($self) = @_; + + return @{ $self->{notes} // [] }; +} + +sub messages { + my ($self) = @_; + + return @{ $self->{messages} // [] }; +} + sub TO_JSON { my ($self) = @_; -- cgit v1.2.3