summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-11-26 20:10:24 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-11-26 20:10:24 +0100
commitbe0380ac6020556120269a0deecba7ffef63dcb0 (patch)
treead5269cad598da7a3b24094d3f16ab4d558e5f9d
parent7085318c1ae616bc2fbd79c335276a0d3420e50f (diff)
Use ::Section module for section data
-rwxr-xr-xbin/dbwagenreihung4
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm5
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Section.pm34
3 files changed, 39 insertions, 4 deletions
diff --git a/bin/dbwagenreihung b/bin/dbwagenreihung
index 0d75fd7..dafefe3 100755
--- a/bin/dbwagenreihung
+++ b/bin/dbwagenreihung
@@ -33,7 +33,7 @@ my $wr = Travel::Status::DE::DBWagenreihung->new(
);
for my $section ($wr->sections) {
- my $section_length = $section->{end_percent} - $section->{start_percent};
+ my $section_length = $section->length_percent;
my $spacing_left = int(($section_length - 2) / 2) - 1;
my $spacing_right = int(($section_length - 2) / 2);
@@ -43,7 +43,7 @@ for my $section ($wr->sections) {
printf("|%s%s%s|",
' ' x $spacing_left,
- $section->{name},
+ $section->name,
' ' x $spacing_right
);
}
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index b97e2bd..608702a 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -9,6 +9,7 @@ our $VERSION = '0.00';
use Carp qw(cluck confess);
use JSON;
use LWP::UserAgent;
+use Travel::Status::DE::DBWagenreihung::Section;
use Travel::Status::DE::DBWagenreihung::Wagon;
sub new {
@@ -92,13 +93,13 @@ sub sections {
for my $section (@{$self->{data}{istformation}{halt}{allSektor}}) {
my $pos = $section->{positionamgleis};
- push(@{$self->{sections}}, {
+ push(@{$self->{sections}}, Travel::Status::DE::DBWagenreihung::Section->new(
name => $section->{sektorbezeichnung},
start_percent => $pos->{startprozent},
end_percent => $pos->{endeprozent},
start_meters => $pos->{startmeter},
end_meters => $pos->{endemeter},
- });
+ ));
}
return @{$self->{sections} // []};
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Section.pm b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
new file mode 100644
index 0000000..780031c
--- /dev/null
+++ b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
@@ -0,0 +1,34 @@
+package Travel::Status::DE::DBWagenreihung::Section;
+
+use strict;
+use warnings;
+use 5.020;
+use utf8;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.00';
+
+Travel::Status::DE::DBWagenreihung::Section->mk_ro_accessors(
+ qw(name start_percent end_percent length_percent start_meters end_meters length_meters)
+);
+
+sub new {
+ my ( $obj, %opt ) = @_;
+ my $ref = \%opt;
+
+ $ref->{length_meters} = $ref->{end_meters} - $ref->{start_meters};
+ $ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent};
+
+ return bless( $ref, $obj );
+}
+
+sub TO_JSON {
+ my ($self) = @_;
+
+ my %copy = %{$self};
+
+ return {%copy};
+}
+
+1;