summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBWagenreihung
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-04-27 18:16:13 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-04-27 18:16:13 +0200
commit11a58c8e0292b45694759a07bd150a0fdb852a8f (patch)
tree7c495f9294b1ef09940e7a64fd55548e61b3bdc1 /lib/Travel/Status/DE/DBWagenreihung
parent4c6612a0656abcc930a82f2d4ea310e16186156c (diff)
Explicitly group wagons, just as the backend does
Diffstat (limited to 'lib/Travel/Status/DE/DBWagenreihung')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Group.pm52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Group.pm b/lib/Travel/Status/DE/DBWagenreihung/Group.pm
new file mode 100644
index 0000000..76fc159
--- /dev/null
+++ b/lib/Travel/Status/DE/DBWagenreihung/Group.pm
@@ -0,0 +1,52 @@
+package Travel::Status::DE::DBWagenreihung::Group;
+
+use strict;
+use warnings;
+use 5.020;
+use utf8;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.13';
+
+Travel::Status::DE::DBWagenreihung::Group->mk_ro_accessors(
+ qw(id train_no type origin destination));
+
+sub new {
+ my ( $obj, %opt ) = @_;
+ my $ref = \%opt;
+
+ return bless( $ref, $obj );
+}
+
+sub set_traintype {
+ my ( $self, $i, $tt ) = @_;
+ $self->{type} = $tt;
+ for my $wagon ( $self->wagons ) {
+ $wagon->set_traintype( $i, $tt );
+ }
+}
+
+sub sort_wagons {
+ my ($self) = @_;
+
+ @{ $self->{wagons} }
+ = sort { $a->{position}{start_percent} <=> $b->{position}{start_percent} }
+ @{ $self->{wagons} };
+}
+
+sub wagons {
+ my ($self) = @_;
+
+ return @{ $self->{wagons} // [] };
+}
+
+sub TO_JSON {
+ my ($self) = @_;
+
+ my %copy = %{$self};
+
+ return {%copy};
+}
+
+1;