summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBWagenreihung
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status/DE/DBWagenreihung')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Group.pm74
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Section.pm2
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Wagon.pm9
3 files changed, 82 insertions, 3 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..dd98550
--- /dev/null
+++ b/lib/Travel/Status/DE/DBWagenreihung/Group.pm
@@ -0,0 +1,74 @@
+package Travel::Status::DE::DBWagenreihung::Group;
+
+use strict;
+use warnings;
+use 5.020;
+use utf8;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.14';
+
+Travel::Status::DE::DBWagenreihung::Group->mk_ro_accessors(
+ qw(id train_no type description desc_short origin destination has_sections)
+);
+
+sub new {
+ my ( $obj, %opt ) = @_;
+ my $ref = \%opt;
+
+ return bless( $ref, $obj );
+}
+
+sub set_description {
+ my ( $self, $desc, $short ) = @_;
+
+ $self->{description} = $desc;
+ $self->{desc_short} = $short;
+}
+
+sub set_sections {
+ my ( $self, @sections ) = @_;
+
+ $self->{sections} = [@sections];
+
+ $self->{has_sections} = 1;
+}
+
+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 sections {
+ my ($self) = @_;
+
+ return @{ $self->{sections} // [] };
+}
+
+sub wagons {
+ my ($self) = @_;
+
+ return @{ $self->{wagons} // [] };
+}
+
+sub TO_JSON {
+ my ($self) = @_;
+
+ my %copy = %{$self};
+
+ return {%copy};
+}
+
+1;
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Section.pm b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
index c93f2dd..5bbf1c9 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Section.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
@@ -7,7 +7,7 @@ use utf8;
use parent 'Class::Accessor';
-our $VERSION = '0.11';
+our $VERSION = '0.14';
Travel::Status::DE::DBWagenreihung::Section->mk_ro_accessors(
qw(name start_percent end_percent length_percent start_meters end_meters length_meters)
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
index ffc3e58..549a5ff 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
@@ -8,7 +8,7 @@ use utf8;
use parent 'Class::Accessor';
use Carp qw(cluck);
-our $VERSION = '0.11';
+our $VERSION = '0.14';
Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
qw(attributes class_type group_index has_ac has_accessibility
has_bahn_comfort has_bike_storage has_bistro has_compartments
@@ -203,7 +203,12 @@ sub parse_type {
sub set_traintype {
my ( $self, $group_index, $tt ) = @_;
- $self->{group_index} = $group_index;
+ $self->{group_index} = $group_index;
+
+ if ( not $tt ) {
+ return;
+ }
+
$self->{train_subtype} = $tt;
if ( not $self->{number} or not exists( $type_attributes{$tt} ) ) {