summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/DBRIS
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS')
-rw-r--r--lib/Travel/Status/DE/DBRIS/Journey.pm45
-rw-r--r--lib/Travel/Status/DE/DBRIS/JourneyAtStop.pm87
-rw-r--r--lib/Travel/Status/DE/DBRIS/Location.pm27
-rw-r--r--lib/Travel/Status/DE/DBRIS/Stop.pm87
4 files changed, 213 insertions, 33 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm
index 47dd726..c4f7df6 100644
--- a/lib/Travel/Status/DE/DBRIS/Journey.pm
+++ b/lib/Travel/Status/DE/DBRIS/Journey.pm
@@ -6,11 +6,11 @@ use 5.020;
use parent 'Class::Accessor';
+use Travel::Status::DE::DBRIS::Location;
+
our $VERSION = '0.01';
-Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(
- qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva id platform rt_platform destination via via_last)
-);
+Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(train is_cancelled));
sub new {
my ( $obj, %opt ) = @_;
@@ -19,36 +19,15 @@ sub new {
my $strptime = $opt{strptime_obj};
my $ref = {
- type => $json->{verkehrmittel}{kurzText},
- line => $json->{verkehrmittel}{mittelText},
- id => $json->{journeyId},
- stop_eva => $json->{bahnhofsId},
- destination => $json->{terminus},
- platform => $json->{gleis},
- rt_platform => $json->{ezGleis},
- via => $json->{ueber},
- via_last => ( $json->{ueber} // [] )->[-1],
+ train => $json->{zugName},
+ is_cancelled => $json->{cancelled},
+ raw_route => $json->{halte},
+ strptime_obj => $strptime,
};
bless( $ref, $obj );
- if ( $json->{zeit} ) {
- $ref->{sched_dep} = $strptime->parse_datetime( $json->{zeit} );
- }
- if ( $json->{ezZeit} ) {
- $ref->{rt_dep} = $strptime->parse_datetime( $json->{ezZeit} );
- }
- $ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep};
-
- if ( $ref->{sched_dep} and $ref->{rt_dep} ) {
- $ref->{delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} )
- ->in_units('minutes');
- }
-
- for my $message ( @{ $json->{meldungen} // [] } ) {
- if ( $message->{type} and $message->{type} eq 'HALT_AUSFALL' ) {
- $ref->{is_cancelled} = 1;
- }
+ for my $message ( @{ $json->{himMeldungen} // [] } ) {
push( @{ $ref->{messages} }, $message );
}
@@ -63,8 +42,12 @@ sub route {
}
@{ $self->{route} }
- = map { Travel::Status::DE::DBRIS::Location->new( json => $_ ) }
- ( @{ $self->{raw_route} // [] },
+ = map {
+ Travel::Status::DE::DBRIS::Location->new(
+ json => $_,
+ strptime_obj => $self->{strptime_obj}
+ )
+ } ( @{ $self->{raw_route} // [] },
@{ $self->{raw_cancelled_route} // [] } );
return @{ $self->{route} };
diff --git a/lib/Travel/Status/DE/DBRIS/JourneyAtStop.pm b/lib/Travel/Status/DE/DBRIS/JourneyAtStop.pm
new file mode 100644
index 0000000..7ab9ed7
--- /dev/null
+++ b/lib/Travel/Status/DE/DBRIS/JourneyAtStop.pm
@@ -0,0 +1,87 @@
+package Travel::Status::DE::DBRIS::JourneyAtStop;
+
+use strict;
+use warnings;
+use 5.020;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.01';
+
+Travel::Status::DE::DBRIS::JourneyAtStop->mk_ro_accessors(
+ qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva id platform rt_platform destination via via_last)
+);
+
+sub new {
+ my ( $obj, %opt ) = @_;
+
+ my $json = $opt{json};
+ my $strptime = $opt{strptime_obj};
+
+ my $ref = {
+ type => $json->{verkehrmittel}{kurzText},
+ line => $json->{verkehrmittel}{mittelText},
+ id => $json->{journeyId},
+ stop_eva => $json->{bahnhofsId},
+ destination => $json->{terminus},
+ platform => $json->{gleis},
+ rt_platform => $json->{ezGleis},
+ via => $json->{ueber},
+ via_last => ( $json->{ueber} // [] )->[-1],
+ };
+
+ bless( $ref, $obj );
+
+ if ( $json->{zeit} ) {
+ $ref->{sched_dep} = $strptime->parse_datetime( $json->{zeit} );
+ }
+ if ( $json->{ezZeit} ) {
+ $ref->{rt_dep} = $strptime->parse_datetime( $json->{ezZeit} );
+ }
+ $ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep};
+
+ if ( $ref->{sched_dep} and $ref->{rt_dep} ) {
+ $ref->{delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} )
+ ->in_units('minutes');
+ }
+
+ for my $message ( @{ $json->{meldungen} // [] } ) {
+ if ( $message->{type} and $message->{type} eq 'HALT_AUSFALL' ) {
+ $ref->{is_cancelled} = 1;
+ }
+ push( @{ $ref->{messages} }, $message );
+ }
+
+ return $ref;
+}
+
+sub route {
+ my ($self) = @_;
+
+ if ( $self->{route} ) {
+ return @{ $self->{route} };
+ }
+
+ @{ $self->{route} }
+ = map { Travel::Status::DE::DBRIS::Location->new( json => $_ ) }
+ ( @{ $self->{raw_route} // [] },
+ @{ $self->{raw_cancelled_route} // [] } );
+
+ return @{ $self->{route} };
+}
+
+sub messages {
+ my ($self) = @_;
+
+ return @{ $self->{messages} // [] };
+}
+
+sub TO_JSON {
+ my ($self) = @_;
+
+ my $ret = { %{$self} };
+
+ return $ret;
+}
+
+1;
diff --git a/lib/Travel/Status/DE/DBRIS/Location.pm b/lib/Travel/Status/DE/DBRIS/Location.pm
index f053f2b..2dfba2c 100644
--- a/lib/Travel/Status/DE/DBRIS/Location.pm
+++ b/lib/Travel/Status/DE/DBRIS/Location.pm
@@ -9,7 +9,9 @@ use parent 'Class::Accessor';
our $VERSION = '0.01';
Travel::Status::DE::DBRIS::Location->mk_ro_accessors(
- qw(eva id lat lon name products type is_cancelled is_additional is_separation display_priority)
+ qw(eva id lat lon name products type is_cancelled is_additional is_separation display_priority
+ dep arr platform
+ )
);
sub new {
@@ -27,9 +29,30 @@ sub new {
type => $json->{type},
is_cancelled => $json->{canceled},
is_additional => $json->{additional},
-
+ platform => $json->{gleis},
+ rt_platform => $json->{ezGleis},
};
+ if ( $json->{abfahrtsZeitpunkt} ) {
+ $ref->{sched_dep}
+ = $opt{strptime_obj}->parse_datetime( $json->{abfahrtsZeitpunkt} );
+ }
+ if ( $json->{ezAbfahrtsZeitpunkt} ) {
+ $ref->{rt_dep}
+ = $opt{strptime_obj}->parse_datetime( $json->{ezAbfahrtsZeitpunkt} );
+ }
+ if ( $json->{ankunftsZeitpunkt} ) {
+ $ref->{sched_arr}
+ = $opt{strptime_obj}->parse_datetime( $json->{ankunftsZeitpunkt} );
+ }
+ if ( $json->{ezAnkunftsZeitpunkt} ) {
+ $ref->{rt_arr}
+ = $opt{strptime_obj}->parse_datetime( $json->{ezAnkunftsZeitpunkt} );
+ }
+
+ $ref->{arr} = $ref->{rt_arr} // $ref->{sched_arr};
+ $ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep};
+
bless( $ref, $obj );
return $ref;
diff --git a/lib/Travel/Status/DE/DBRIS/Stop.pm b/lib/Travel/Status/DE/DBRIS/Stop.pm
new file mode 100644
index 0000000..d717ec4
--- /dev/null
+++ b/lib/Travel/Status/DE/DBRIS/Stop.pm
@@ -0,0 +1,87 @@
+package Travel::Status::DE::DBRIS::Stop;
+
+use strict;
+use warnings;
+use 5.020;
+
+use parent 'Class::Accessor';
+
+our $VERSION = '0.01';
+
+Travel::Status::DE::DBRIS::Stop->mk_ro_accessors(
+ qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva id platform rt_platform destination via via_last)
+);
+
+sub new {
+ my ( $obj, %opt ) = @_;
+
+ my $json = $opt{json};
+ my $strptime = $opt{strptime_obj};
+
+ my $ref = {
+ type => $json->{verkehrmittel}{kurzText},
+ line => $json->{verkehrmittel}{mittelText},
+ id => $json->{journeyId},
+ stop_eva => $json->{bahnhofsId},
+ destination => $json->{terminus},
+ platform => $json->{gleis},
+ rt_platform => $json->{ezGleis},
+ via => $json->{ueber},
+ via_last => ( $json->{ueber} // [] )->[-1],
+ };
+
+ bless( $ref, $obj );
+
+ if ( $json->{zeit} ) {
+ $ref->{sched_dep} = $strptime->parse_datetime( $json->{zeit} );
+ }
+ if ( $json->{ezZeit} ) {
+ $ref->{rt_dep} = $strptime->parse_datetime( $json->{ezZeit} );
+ }
+ $ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep};
+
+ if ( $ref->{sched_dep} and $ref->{rt_dep} ) {
+ $ref->{delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} )
+ ->in_units('minutes');
+ }
+
+ for my $message ( @{ $json->{meldungen} // [] } ) {
+ if ( $message->{type} and $message->{type} eq 'HALT_AUSFALL' ) {
+ $ref->{is_cancelled} = 1;
+ }
+ push( @{ $ref->{messages} }, $message );
+ }
+
+ return $ref;
+}
+
+sub route {
+ my ($self) = @_;
+
+ if ( $self->{route} ) {
+ return @{ $self->{route} };
+ }
+
+ @{ $self->{route} }
+ = map { Travel::Status::DE::DBRIS::Location->new( json => $_ ) }
+ ( @{ $self->{raw_route} // [] },
+ @{ $self->{raw_cancelled_route} // [] } );
+
+ return @{ $self->{route} };
+}
+
+sub messages {
+ my ($self) = @_;
+
+ return @{ $self->{messages} // [] };
+}
+
+sub TO_JSON {
+ my ($self) = @_;
+
+ my $ret = { %{$self} };
+
+ return $ret;
+}
+
+1;