summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBWagenreihung/Group.pm
blob: 76fc159142ea3068ef74ac0c31d3908982d71126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;