From a372ea0e36a7bde124084477a67d27bc063cdd48 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 2 Sep 2023 12:45:53 +0200 Subject: Result: TO_JSON: include simplified wing and replacement / replaced refs --- lib/Travel/Status/DE/IRIS/Result.pm | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm index 3d8b416..442dd1a 100644 --- a/lib/Travel/Status/DE/IRIS/Result.pm +++ b/lib/Travel/Status/DE/IRIS/Result.pm @@ -876,13 +876,35 @@ sub TO_JSON { my ($self) = @_; my %copy = %{$self}; - delete $copy{arrival_wings}; - delete $copy{departure_wings}; delete $copy{realtime_xml}; - delete $copy{replaced_by}; - delete $copy{replacement_for}; delete $copy{strptime_obj}; + + for my $ref_key ( + qw(arrival_wings departure_wings replaced_by replacement_for)) + { + delete $copy{$ref_key}; + for my $train_ref ( @{ $self->{$ref_key} // [] } ) { + push( + @{ $copy{$ref_key} }, + { + raw_id => $train_ref->raw_id, + train => $train_ref->train, + train_no => $train_ref->train_no, + type => $train_ref->type, + } + ); + } + } + delete $copy{wing_of}; + if ( my $train_ref = $self->wing_of ) { + $copy{wing_of} = { + raw_id => $train_ref->raw_id, + train => $train_ref->train, + train_no => $train_ref->train_no, + type => $train_ref->type, + }; + } for my $datetime_key ( qw(arrival departure sched_arrival sched_departure start datetime)) -- cgit v1.2.3