diff options
Diffstat (limited to 'lib/WebService/TFL/Bus')
-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; |