| 1 | package Travel::Status::DE::DBWagenreihung::Sector; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use 5.020; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | use parent 'Class::Accessor'; | ||
| 9 | |||
| 10 | our $VERSION = '0.18'; | ||
| 11 | |||
| 12 | Travel::Status::DE::DBWagenreihung::Sector->mk_ro_accessors( | ||
| 13 | qw(name start_percent end_percent length_percent start_meters end_meters length_meters cube_meters cube_percent) | ||
| 14 | ); | ||
| 15 | |||
| 16 | sub new { | ||
| 17 | my ( $obj, %opt ) = @_; | ||
| 18 | |||
| 19 | my %section = %{ $opt{json} }; | ||
| 20 | my %platform = %{ $opt{platform} }; | ||
| 21 | |||
| 22 | my $platform_length = $platform{end} - $platform{start}; | ||
| 23 | |||
| 24 | my $ref = { | ||
| 25 | name => $section{name}, | ||
| 26 | start_meters => $section{start}, | ||
| 27 | end_meters => $section{end}, | ||
| 28 | length_meters => $section{end} - $section{start}, | ||
| 29 | cube_meters => $section{cubePosition}, | ||
| 30 | start_percent => ( $section{start} - $platform{start} ) | ||
| 31 | * 100 / $platform_length, | ||
| 32 | end_percent => ( $section{end} - $platform{start} ) | ||
| 33 | * 100 / $platform_length, | ||
| 34 | cube_percent => ( $section{cubePosition} - $platform{start} ) | ||
| 35 | * 100 / $platform_length, | ||
| 36 | }; | ||
| 37 | |||
| 38 | $ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent}; | ||
| 39 | |||
| 40 | return bless( $ref, $obj ); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub TO_JSON { | ||
| 44 | my ($self) = @_; | ||
| 45 | |||
| 46 | my %copy = %{$self}; | ||
| 47 | |||
| 48 | return {%copy}; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; |