diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-29 21:58:16 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-29 21:58:16 +0100 |
commit | a5b392d6866557bc0dffc948d804f21a7543aa21 (patch) | |
tree | 81936710b9d5cfb555eb20c8e52e01f1c6f2e41b /lib/Travel/Status/DE/DBRIS/Formation/Sector.pm | |
parent | 9392e11dcb7843b3ce04e9014864e0486dba6cef (diff) |
merge DBWagenreihung modules into DBRIS; they both use bahn.de
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS/Formation/Sector.pm')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Formation/Sector.pm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Formation/Sector.pm b/lib/Travel/Status/DE/DBRIS/Formation/Sector.pm new file mode 100644 index 0000000..ac01647 --- /dev/null +++ b/lib/Travel/Status/DE/DBRIS/Formation/Sector.pm @@ -0,0 +1,52 @@ +package Travel::Status::DE::DBRIS::Formation::Sector; + +use strict; +use warnings; +use 5.020; +use utf8; + +use parent 'Class::Accessor'; + +our $VERSION = '0.18'; + +Travel::Status::DE::DBRIS::Formation::Sector->mk_ro_accessors( + qw(name start_percent end_percent length_percent start_meters end_meters length_meters cube_meters cube_percent) +); + +sub new { + my ( $obj, %opt ) = @_; + + my %section = %{ $opt{json} }; + my %platform = %{ $opt{platform} }; + + my $platform_length = $platform{end} - $platform{start}; + + my $ref = { + name => $section{name}, + start_meters => $section{start}, + end_meters => $section{end}, + length_meters => $section{end} - $section{start}, + cube_meters => $section{cubePosition}, + start_percent => ( $section{start} - $platform{start} ) + * 100 / $platform_length, + end_percent => ( $section{end} - $platform{start} ) + * 100 / $platform_length, + cube_percent => ( $section{cubePosition} - $platform{start} ) + * 100 / $platform_length, + }; + + $ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent}; + + return bless( $ref, $obj ); +} + +sub TO_JSON { + my ($self) = @_; + + my %copy = %{$self}; + + return {%copy}; +} + +1; + |