Unverified Commit 93497011 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Journey: Add id accessor; try retrieving line number from ID if missing

parent 1d5c3fc0
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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},
+9 −1
Original line number Diff line number Diff line
@@ -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} // [] } ) {