diff options
author | dakkar <dakkar@thenautilus.net> | 2024-02-03 16:09:55 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2024-02-03 16:09:55 +0000 |
commit | 0894f68085a8ef9bfd3c673339416c014be02f85 (patch) | |
tree | b839a26128d69438198a24ae098e30892278e1f2 /lib/WebService/TFL | |
parent | more cleaning (diff) | |
download | HomePanel-0894f68085a8ef9bfd3c673339416c014be02f85.tar.gz HomePanel-0894f68085a8ef9bfd3c673339416c014be02f85.tar.bz2 HomePanel-0894f68085a8ef9bfd3c673339416c014be02f85.zip |
show more than 1 bus stop
Diffstat (limited to 'lib/WebService/TFL')
-rw-r--r-- | lib/WebService/TFL/Bus/Prediction.pm | 2 | ||||
-rw-r--r-- | lib/WebService/TFL/Bus/Response.pm | 20 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/WebService/TFL/Bus/Prediction.pm b/lib/WebService/TFL/Bus/Prediction.pm index 670baf7..8873b02 100644 --- a/lib/WebService/TFL/Bus/Prediction.pm +++ b/lib/WebService/TFL/Bus/Prediction.pm @@ -4,7 +4,7 @@ use Types::Standard -all; use Types::DateTime -all; use namespace::clean; -has [qw(stationName lineName towards)] => ( +has [qw(stationName destinationName lineName towards)] => ( is => 'ro', isa => Str, required => 1, diff --git a/lib/WebService/TFL/Bus/Response.pm b/lib/WebService/TFL/Bus/Response.pm index 0f811fc..59582be 100644 --- a/lib/WebService/TFL/Bus/Response.pm +++ b/lib/WebService/TFL/Bus/Response.pm @@ -9,12 +9,20 @@ has predictions => ( isa => ArrayRef[InstanceOf['WebService::TFL::Bus::Prediction']], ); +sub _sort { + return sort { + $a->destinationName cmp $b->destinationName + || + $a->expectedArrival <=> $b->expectedArrival + } @_; +} + sub new_from_response { my ($class,$response_data) = @_; return $class->new({ predictions => [ - sort { $a->expectedArrival <=> $b->expectedArrival } + _sort map { WebService::TFL::Bus::Prediction->new_from_response($_) } grep { $_->{'$type'} =~ /\bPrediction\b/ } $response_data->@* @@ -22,4 +30,14 @@ sub new_from_response { }); } +sub new_merged { + my ($class, @responses) = @_; + + return $class->new({ + predictions => [ + _sort map { $_->predictions->@* } @responses + ], + }); +} + 1; |