Commit b066c814 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add some type parsing

parent ca490a14
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -122,4 +122,10 @@ for my $wagon ( $wr->wagons ) {
		$col_reset,          ' ' x $spacing_right );
}
print $wr->direction == 100 ? '>' : '<';
print "\n";
print "\n\n";

for my $wagon ( $wr->wagons ) {
	printf( "%3s: %10s  %s\n",
		$wagon->number || '?',
		$wagon->type, join( q{  }, $wagon->attributes ) );
}
+65 −2
Original line number Diff line number Diff line
@@ -11,7 +11,9 @@ use Carp qw(cluck);
our $VERSION = '0.00';

Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
	qw(class_type has_bistro is_locomotive is_powercar number section));
	qw(attributes class_type has_ac has_accessibility has_bistro
	has_multipurpose is_dosto is_interregio is_locomotive is_powercar number
	section type));

sub new {
	my ( $obj, %opt ) = @_;
@@ -25,6 +27,10 @@ sub new {
	$ref->{section}       = $opt{fahrzeugsektor};
	$ref->{type}          = $opt{fahrzeugtyp};

	my $self = bless($ref, $obj);

	$self->parse_type;

	if ( $opt{kategorie} =~ m{SPEISEWAGEN} ) {
		$ref->{has_bistro} = 1;
	}
@@ -52,7 +58,64 @@ sub new {
	$ref->{position}{start_meters}  = $pos->{startmeter};
	$ref->{position}{end_meters}    = $pos->{endemeter};

	return bless( $ref, $obj );
	return $self;
}

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

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

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

	my $type = $self->{type};
	my @desc;

	# Thanks to <https://www.deutsche-reisezugwagen.de/lexikon/erklarung-der-gattungszeichen/>

	if ($type =~ m{^D}) {
		$self->{is_dosto} = 1;
		push(@desc, 'Doppelstock');
	}

	if ($type =~ m{b}) {
		$self->{has_accessibility} = 1;
		push(@desc, 'Behindertengerechte Ausstattung');
	}

	if ($type =~ m{d}) {
		$self->{has_multipurpose} = 1;
		push(@desc, 'Mehrzweckraum');
	}

	if ($type =~ m{f}) {
		push(@desc, 'Steuerabteil');
	}

	if ($type =~ m{i}) {
		$self->{is_interregio} = 1;
		push(@desc, 'Interregiowagen');
	}

	if ($type =~ m{m}) {
		# ?
	}

	if ($type =~ m{p}) {
		$self->{has_ac} = 1;
		push(@desc, 'klimatisiert');
		push(@desc, 'Großraum');
	}

	if ($type =~ m{v}) {
		$self->{has_ac} = 1;
		push(@desc, 'klimatisiert');
		push(@desc, 'Abteilwagen');
	}

	$self->{attributes} = \@desc;
}

sub is_first_class {