From 3f726df6638ec9cbe0b43a5b0988a06af749de70 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 30 Jul 2024 14:55:36 +0200 Subject: Carriage: re-add class and amenity accessors --- lib/Travel/Status/DE/DBWagenreihung/Carriage.pm | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib') diff --git a/lib/Travel/Status/DE/DBWagenreihung/Carriage.pm b/lib/Travel/Status/DE/DBWagenreihung/Carriage.pm index 8c93fed..df8b1d7 100644 --- a/lib/Travel/Status/DE/DBWagenreihung/Carriage.pm +++ b/lib/Travel/Status/DE/DBWagenreihung/Carriage.pm @@ -13,9 +13,24 @@ Travel::Status::DE::DBWagenreihung::Carriage->mk_ro_accessors( qw(class_type is_closed is_dosto is_locomotive is_powercar number model section uic_id type start_meters end_meters length_meters start_percent end_percent length_percent + has_priority_seats has_ac has_quiet_zone has_bahn_comfort has_wheelchair_space + has_wheelchair_toilet has_family_zone has_infant_cabin has_info has_bistro + has_first_class has_second_class ) ); +my %type_map = ( + SEATS_SEVERELY_DISABLE => 'priority_seats', + AIR_CONDITION => 'ac', + ZONE_QUIET => 'quiet_zone', + SEATS_BAHN_COMFORT => 'bahn_comfort', + INFO => 'info', + TOILET_WHEELCHAIR => 'wheelchair_toilet', + WHEELCHAIR_SPACE => 'wheelchair_space', + ZONE_FAMILY => 'family_zone', + CABIN_INFANT => 'infant_cabin', +); + sub new { my ( $obj, %opt ) = @_; my $ref = {}; @@ -40,6 +55,14 @@ sub new { $self->parse_type; + for my $amenity ( @{ $json{amenities} // [] } ) { + my $type = $amenity->{type}; + if ( $type_map{$type} ) { + my $key = 'has_' . $type_map{$type}; + $self->{$key} = 1; + } + } + if ( $json{status} and $json{status} eq 'CLOSED' ) { $ref->{is_closed} = 1; } @@ -54,6 +77,9 @@ sub new { $ref->{is_powercar} = 1; } + $ref->{has_first_class} = $json{type}{hasFirstClass}; + $ref->{has_second_class} = $json{type}{hasEconomyClass}; + if ( $ref->{type} =~ m{AB} ) { $ref->{class_type} = 12; } -- cgit v1.2.3