Commit 481d3f9c authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add train classes

parent acaf6fec
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -27,10 +27,16 @@ if (@trains != 1) {

my $wr = Travel::Status::DE::DBWagenreihung->new(
	departure => $trains[0]->sched_departure,
	developer_mode => 1,
	train_number => $train_number,
);

for my $wagon ($wr->wagons) {
	printf("%s %s\n", $wagon->number, $wagon->section);
	printf("%s %2s", $wagon->section, $wagon->number || 'X');
	if ($wagon->class_type == 12) {
		print(" 1/2");
	}
	elsif ($wagon->class_type) {
		printf(" %d", $wagon->class_type);
	}
	print("\n");
}
+36 −2
Original line number Diff line number Diff line
@@ -8,22 +8,56 @@ use utf8;
use parent 'Class::Accessor';
use Carp qw(cluck);

our $VERSION = '1.21';
our $VERSION = '0.00';

Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
	qw(number section)
	qw(class_type has_bistro number section)
);

sub new {
	my ( $obj, %opt ) = @_;
	my $ref = \%opt;

	$ref->{class_type} = 0;
	$ref->{has_bistro} = 0;
	$ref->{number} = $ref->{wagenordnungsnummer};
	$ref->{section} = $ref->{fahrzeugsektor};

	if ($ref->{kategorie} =~ m{SPEISEWAGEN}) {
		$ref->{has_bistro} = 1;
	}

	if ($ref->{fahrzeugtyp} =~ m{^AB}) {
		$ref->{class_type} = 12;
	}
	elsif ($ref->{fahrzeugtyp} =~ m{^A}) {
		$ref->{class_type} = 1;
	}
	elsif ($ref->{fahrzeugtyp} =~ m{^B|^WR}) {
		$ref->{class_type} = 2;
	}

	return bless( $ref, $obj );
}

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

	if ($self->{fahrzeugtyp} =~ m{^A}) {
		return 1;
	}
	return 0;
}

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

	if ($self->{fahrzeugtyp} =~ m{^A?B}) {
		return 1;
	}
	return 0;
}

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