summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
blob: a29d42aa3810cc69b25b335840cbf90bd0c71544 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package Travel::Status::DE::DBWagenreihung::Wagon;

use strict;
use warnings;
use 5.020;
use utf8;

use parent 'Class::Accessor';
use Carp qw(cluck);

our $VERSION = '0.00';

Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
	qw(class_type has_bistro number section)
);

sub new {
	my ( $obj, %opt ) = @_;
	my $ref = \%opt;

	$ref->{class_type} = 0;
	$ref->{has_bistro} = 0;
	$ref->{number} = $ref->{wagenordnungsnummer};
	$ref->{section} = $ref->{fahrzeugsektor};

	if ($ref->{kategorie} =~ m{SPEISEWAGEN}) {
		$ref->{has_bistro} = 1;
	}

	if ($ref->{fahrzeugtyp} =~ m{^AB}) {
		$ref->{class_type} = 12;
	}
	elsif ($ref->{fahrzeugtyp} =~ m{^A}) {
		$ref->{class_type} = 1;
	}
	elsif ($ref->{fahrzeugtyp} =~ m{^B|^WR}) {
		$ref->{class_type} = 2;
	}

	return bless( $ref, $obj );
}

sub is_first_class {
	my ($self) = @_;

	if ($self->{fahrzeugtyp} =~ m{^A}) {
		return 1;
	}
	return 0;
}

sub is_second_class {
	my ($self) = @_;

	if ($self->{fahrzeugtyp} =~ m{^A?B}) {
		return 1;
	}
	return 0;
}

sub sections {
	my ($self) = @_;

	return @{$self->{sections}};
}

sub TO_JSON {
	my ($self) = @_;

	my %copy = %{$self};

	return {%copy};
}

1;