summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm25
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Wagon.pm31
2 files changed, 45 insertions, 11 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index 68dbd69..b97e2bd 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -67,9 +67,6 @@ sub get_wagonorder {
return;
}
my $json = $self->{json}->decode($content);
- if ($self->{developer_mode}) {
- say $self->{json}->pretty->encode($json);
- }
if (exists $json->{error}) {
$self->{errstr} = 'Backend error: ' . $json->{error}{msg};
@@ -86,6 +83,27 @@ sub error {
return $self->{errstr};
}
+sub sections {
+ my ($self) = @_;
+
+ if (exists $self->{sections}) {
+ return @{$self->{sections}};
+ }
+
+ for my $section (@{$self->{data}{istformation}{halt}{allSektor}}) {
+ my $pos = $section->{positionamgleis};
+ push(@{$self->{sections}}, {
+ name => $section->{sektorbezeichnung},
+ start_percent => $pos->{startprozent},
+ end_percent => $pos->{endeprozent},
+ start_meters => $pos->{startmeter},
+ end_meters => $pos->{endemeter},
+ });
+ }
+
+ return @{$self->{sections} // []};
+}
+
sub wagons {
my ($self) = @_;
@@ -98,6 +116,7 @@ sub wagons {
push(@{$self->{wagons}}, Travel::Status::DE::DBWagenreihung::Wagon->new(%{$wagon}));
}
}
+ @{$self->{wagons}} = sort { $a->{position}->{start_percent} <=> $b->{position}->{start_percent} } @{$self->{wagons}};
return @{$self->{wagons} // []};
}
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
index a29d42a..0cda4f3 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
@@ -11,32 +11,47 @@ use Carp qw(cluck);
our $VERSION = '0.00';
Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
- qw(class_type has_bistro number section)
+ qw(class_type has_bistro is_locomotive is_powercar number section)
);
sub new {
my ( $obj, %opt ) = @_;
- my $ref = \%opt;
+ my $ref = {};
$ref->{class_type} = 0;
$ref->{has_bistro} = 0;
- $ref->{number} = $ref->{wagenordnungsnummer};
- $ref->{section} = $ref->{fahrzeugsektor};
+ $ref->{is_locomotive} = 0;
+ $ref->{is_powercar} = 0;
+ $ref->{number} = $opt{wagenordnungsnummer};
+ $ref->{section} = $opt{fahrzeugsektor};
- if ($ref->{kategorie} =~ m{SPEISEWAGEN}) {
+ if ($opt{kategorie} =~ m{SPEISEWAGEN}) {
$ref->{has_bistro} = 1;
}
+ elsif ($opt{kategorie} eq 'LOK') {
+ $ref->{is_locomotive} = 1;
+ }
+ elsif ($opt{kategorie} eq 'TRIEBKOPF') {
+ $ref->{is_powercar} = 1;
+ }
- if ($ref->{fahrzeugtyp} =~ m{^AB}) {
+ if ($opt{fahrzeugtyp} =~ m{AB}) {
$ref->{class_type} = 12;
}
- elsif ($ref->{fahrzeugtyp} =~ m{^A}) {
+ elsif ($opt{fahrzeugtyp} =~ m{A}) {
$ref->{class_type} = 1;
}
- elsif ($ref->{fahrzeugtyp} =~ m{^B|^WR}) {
+ elsif ($opt{fahrzeugtyp} =~ m{B|WR}) {
$ref->{class_type} = 2;
}
+ my $pos = $opt{positionamhalt};
+
+ $ref->{position}{start_percent} = $pos->{startprozent};
+ $ref->{position}{end_percent} = $pos->{endeprozent};
+ $ref->{position}{start_meters} = $pos->{startmeter};
+ $ref->{position}{end_meters} = $pos->{endemeter};
+
return bless( $ref, $obj );
}