diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-12-27 15:25:27 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-12-27 15:25:27 +0100 |
commit | b066c8145dfb091f073d91ca1ed043847d0c390b (patch) | |
tree | 67ad0e602f6b6b06155e09da082ae0088a1e032a | |
parent | ca490a14daae934d4e846d900a8dde40cab2fc46 (diff) |
add some type parsing
-rwxr-xr-x | bin/db-wagenreihung | 10 | ||||
-rw-r--r-- | lib/Travel/Status/DE/DBWagenreihung/Wagon.pm | 67 |
2 files changed, 73 insertions, 4 deletions
diff --git a/bin/db-wagenreihung b/bin/db-wagenreihung index 959e217..2594478 100755 --- a/bin/db-wagenreihung +++ b/bin/db-wagenreihung @@ -43,7 +43,7 @@ my ( $station, $train_number ) = @ARGV; my $col_first = "\e[38;5;11m"; my $col_mixed = "\e[38;5;208m"; -my $col_second = "\e[0m"; #"\e[38;5;9m"; +my $col_second = "\e[0m"; #"\e[38;5;9m"; my $col_reset = "\e[0m"; my $res = Travel::Status::DE::IRIS->new( @@ -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 ) ); +} diff --git a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm index 850bc84..0f92500 100644 --- a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm +++ b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm @@ -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 { |