diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-03-24 18:20:54 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-03-24 18:20:54 +0100 |
commit | 93497011d13076c70d5bf58a1fa045560a4dc815 (patch) | |
tree | d010dee9f8c8688cf53c3061fa0000177bb7f300 | |
parent | 1d5c3fc0c9732043207c1dd20bac42534f214ec7 (diff) |
Journey: Add id accessor; try retrieving line number from ID if missing
-rw-r--r-- | lib/Travel/Status/DE/DBRIS.pm | 7 | ||||
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 10 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm index 9691dbd..117155c 100644 --- a/lib/Travel/Status/DE/DBRIS.pm +++ b/lib/Travel/Status/DE/DBRIS.pm @@ -153,7 +153,7 @@ sub new { $self->parse_stationboard; } elsif ( $conf{journey} ) { - $self->parse_journey; + $self->parse_journey( id => $conf{journey} ); } elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; @@ -194,7 +194,7 @@ sub new_p { $self->parse_stationboard; } elsif ( $conf{journey} ) { - $self->parse_journey; + $self->parse_journey( id => $conf{journey} ); } elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; @@ -312,9 +312,10 @@ sub get_with_cache_p { } sub parse_journey { - my ($self) = @_; + my ( $self, %opt ) = @_; $self->{result} = Travel::Status::DE::DBRIS::Journey->new( + id => $opt{id}, json => $self->{raw_json}, 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 9c7d10c..ae4a0ee 100644 --- a/lib/Travel/Status/DE/DBRIS/Journey.pm +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -11,7 +11,7 @@ use Travel::Status::DE::DBRIS::Location; our $VERSION = '0.07'; Travel::Status::DE::DBRIS::Journey->mk_ro_accessors( - qw(day train type number is_cancelled)); + qw(day id train type number is_cancelled)); sub new { my ( $obj, %opt ) = @_; @@ -21,6 +21,7 @@ sub new { my $strptime = $opt{strptime_obj}; my $ref = { + id => $opt{id}, day => $strpdate->parse_datetime( $json->{reisetag} ), train => $json->{zugName}, is_cancelled => $json->{cancelled}, @@ -33,6 +34,13 @@ sub new { # with no way of distinguishing between those ( $ref->{type}, $ref->{number} ) = split( qr{\s+}, $ref->{train} ); + # The line number seems to be encoded in the trip ID + if ( not defined $ref->{number} + and $opt{id} =~ m{ [#] ZE [#] (?<line> [^#]+ ) [#] ZB [#] }x ) + { + $ref->{number} = $+{line}; + } + bless( $ref, $obj ); for my $message ( @{ $json->{himMeldungen} // [] } ) { |