diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-09-02 12:45:53 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-09-02 12:45:53 +0200 |
commit | a372ea0e36a7bde124084477a67d27bc063cdd48 (patch) | |
tree | 7c9ab3da1bd6bd17ec0b6a71b59df480a567a06a /lib/Travel/Status/DE/IRIS/Result.pm | |
parent | ecdd2cadadd30ba09dbeafd7ce826e94061cdd2c (diff) |
Result: TO_JSON: include simplified wing and replacement / replaced refs
Diffstat (limited to 'lib/Travel/Status/DE/IRIS/Result.pm')
-rw-r--r-- | lib/Travel/Status/DE/IRIS/Result.pm | 30 |
1 files 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)) |