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

journey: parse trip day and attributes

parent 0c914061
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -211,8 +211,7 @@ elsif ( $opt{journey} ) {
		}
	}

	say $trip->train;
	say q{};
	printf( "%s am %s\n\n", $trip->train, $trip->day->strftime('%d.%m.%Y') );

	for my $stop ( $trip->route ) {
		if ( $stop == $mark_stop ) {
@@ -242,6 +241,12 @@ elsif ( $opt{journey} ) {
			print($output_reset);
		}
	}
	if ( $trip->attributes ) {
		say q{};
	}
	for my $attr ( $trip->attributes ) {
		say $attr->{value};
	}
	if ( $trip->messages ) {
		say q{};
	}
+7 −1
Original line number Diff line number Diff line
@@ -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},
	);
}

+13 −1
Original line number Diff line number Diff line
@@ -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) = @_;