summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 14:55:36 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 14:55:36 +0200
commit3f726df6638ec9cbe0b43a5b0988a06af749de70 (patch)
tree1c1b0fb7752416be856eee2e0092fd365cb30d8d /lib
parent3304b226c3002a29f12cb8a74d4c75a6ba7225d8 (diff)
Carriage: re-add class and amenity accessors
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Carriage.pm26
1 files changed, 26 insertions, 0 deletions
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;
}