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

Always parse wagons

parent f2aa75d3
Loading
Loading
Loading
Loading
+8 −27
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ use Travel::Status::DE::DBWagenreihung::Wagon;
our $VERSION = '0.12';

Travel::Status::DE::DBWagenreihung->mk_ro_accessors(
	qw(platform station train_no train_type));
	qw(direction platform station train_no train_type));

my %is_redesign = (
	"02" => 1,
@@ -197,6 +197,8 @@ sub parse_wagonorder {

	$self->{train_type} = $self->{data}{istformation}{zuggattung};
	$self->{train_no}   = $self->{data}{istformation}{zugnummer};

	$self->parse_wagons;
}

sub errstr {
@@ -209,13 +211,11 @@ sub TO_JSON {
	my ($self) = @_;

	# ensure that all objects are available
	$self->direction;
	$self->origins;
	$self->destinations;
	$self->train_numbers;
	$self->train_descriptions;
	$self->sections;
	$self->wagons;

	my %copy = %{$self};

@@ -224,18 +224,6 @@ sub TO_JSON {
	return {%copy};
}

sub direction {
	my ($self) = @_;

	if ( not exists $self->{direction} ) {

		# direction is set while parsing wagons
		$self->wagons;
	}

	return $self->{direction};
}

sub has_bad_wagons {
	my ($self) = @_;

@@ -393,12 +381,6 @@ sub train_descriptions {
		return @{ $self->{train_descriptions} };
	}

	if ( not exists $self->{wagons} ) {

		# wagongroups are set while parsong wagons
		$self->wagons;
	}

	for my $wagons ( @{ $self->{wagongroups} } ) {
		my ( $short, $desc ) = $self->wagongroup_description( @{$wagons} );
		my @sections = uniq map { $_->section } @{$wagons};
@@ -663,11 +645,12 @@ sub wagongroup_subtype {

sub wagons {
	my ($self) = @_;

	if ( exists $self->{wagons} ) {
		return @{ $self->{wagons} };
	return @{ $self->{wagons} // [] };
}

sub parse_wagons {
	my ($self) = @_;

	my @wagon_groups;

	for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
@@ -711,8 +694,6 @@ sub wagons {
	}

	$self->{wagongroups} = [@wagon_groups];

	return @{ $self->{wagons} // [] };
}

sub get_with_cache {
@@ -931,7 +912,7 @@ L<https://github.com/derf/Travel-Status-DE-DBWagenreihung>

=head1 AUTHOR

Copyright (C) 2018-2019 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
Copyright (C) 2018-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>

=head1 LICENSE