blob: 53d351382d50d9781c3f48924c3cd7790da0eff2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package Travel::Status::DE::DBWagenreihung::Sector;
use strict;
use warnings;
use 5.020;
use utf8;
use parent 'Class::Accessor';
our $VERSION = '0.17';
Travel::Status::DE::DBWagenreihung::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;
|