summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-01-04 19:19:10 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-01-04 19:19:10 +0100
commitc1d880d84e93d5c60098b2e3de909a950b78023c (patch)
treeec0ef38bab0d6297e30c62cabb5eca176d047eda
parenta92a2b0d5583114cd3d86660af6a81f19223b003 (diff)
Departure: Add "id" accessor
-rwxr-xr-xbin/efa-m6
-rw-r--r--lib/Travel/Status/DE/EFA/Departure.pm21
2 files changed, 22 insertions, 5 deletions
diff --git a/bin/efa-m b/bin/efa-m
index 057cfc9..7777832 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -483,11 +483,7 @@ sub show_results {
@output_line = ( $dtime, $platform, $line, q{}, $d->destination, $d );
if ($show_jid) {
- $output_line[2] .= sprintf( ' %s@%d(%s)%d',
- $d->stateless =~ s{ }{}gr,
- scalar $d->route_pre ? ( $d->route_pre )[0]->id : $d->stop_id,
- $d->sched_datetime->strftime('%Y%m%d'),
- $d->key );
+ $output_line[2] .= ' ' . $d->id;
}
if ( $edata{route} ) {
diff --git a/lib/Travel/Status/DE/EFA/Departure.pm b/lib/Travel/Status/DE/EFA/Departure.pm
index e75ae07..fb7b374 100644
--- a/lib/Travel/Status/DE/EFA/Departure.pm
+++ b/lib/Travel/Status/DE/EFA/Departure.pm
@@ -167,6 +167,20 @@ sub parse_route {
return \@ret;
}
+sub id {
+ my ($self) = @_;
+
+ if ( $self->{id} ) {
+ return $self->{id};
+ }
+
+ return $self->{id} = sprintf( '%s@%d(%s)%d',
+ $self->stateless =~ s{ }{}gr,
+ scalar $self->route_pre ? ( $self->route_pre )[0]->id : $self->stop_id,
+ $self->sched_datetime->strftime('%Y%m%d'),
+ $self->key );
+}
+
sub hints {
my ($self) = @_;
@@ -324,6 +338,13 @@ Additional information related to the departure (list of strings). If
departures for an address were requested, this is the stop name, otherwise it
may be recent news related to the line's schedule.
+=item $departure->id
+
+Stringified unique(?) identifier of this departure; suitable for passing to
+Travel::Status::DE::EFA->new(stopseq) after decomposing it again.
+The returned string combines B<stateless>, B<stop_id> (or the ID of the first
+stop in B<route_pre>, if present), B<sched_datetime>, and B<key>.
+
=item $departure->is_cancelled
1 if the departure got cancelled, 0 otherwise.