diff options
-rwxr-xr-x | bin/efa | 21 | ||||
-rw-r--r-- | lib/Travel/Routing/DE/VRR.pm | 18 | ||||
-rw-r--r-- | lib/Travel/Routing/DE/VRR/Route.pm | 6 |
3 files changed, 40 insertions, 5 deletions
@@ -6,6 +6,8 @@ use strict; use warnings; use 5.010; +use utf8; + use Travel::Routing::DE::VRR; use Exception::Class; use Getopt::Long qw/:config no_ignore_case/; @@ -112,6 +114,7 @@ GetOptions( date|d=s depart=s exclude|e=s@ + extended-info|E from=s@{2} help|h ignore-info|I:s @@ -188,7 +191,23 @@ check_for_error($@); my @routes = $efa->routes; for my $i ( 0 .. $#routes ) { - for my $c ( $routes[$i]->parts ) { + + my $route = $routes[$i]; + + if ($opt->{'extended-info'}) { + print '# ' . $route->duration; + if ($route->ticket_type) { + printf(", class %s (%s€ / %s€)\n\n", + $route->ticket_type, + $route->fare_adult, $route->fare_child, + ); + } + else { + print "\n\n"; + } + } + + for my $c ( $route->parts ) { for my $extra ( $c->extra ) { diff --git a/lib/Travel/Routing/DE/VRR.pm b/lib/Travel/Routing/DE/VRR.pm index 7a0abef..45776fa 100644 --- a/lib/Travel/Routing/DE/VRR.pm +++ b/lib/Travel/Routing/DE/VRR.pm @@ -432,8 +432,6 @@ sub itdtime_str { sub parse_part { my ($self, $route) = @_; - my $info; - my $xp_route = XML::LibXML::XPathExpression->new('./itdPartialRouteList/itdPartialRoute'); my $xp_dep = XML::LibXML::XPathExpression->new('./itdPoint[@usage="departure"]'); my $xp_arr = XML::LibXML::XPathExpression->new('./itdPoint[@usage="arrival"]'); @@ -444,11 +442,23 @@ sub parse_part { my $xp_mot = XML::LibXML::XPathExpression->new('./itdMeansOfTransport'); my $xp_info = XML::LibXML::XPathExpression->new('./itdInfoTextList/infoTextListElem'); + my $xp_fare = XML::LibXML::XPathExpression->new('./itdFare/itdSingleTicket'); my @route_parts; - $info->{vehicle_time} = $route->getAttribute('vehicleTime'); - $info->{duration} = $route->getAttribute('publicDuration'); + my $info = { + duration => $route->getAttribute('publicDuration'), + vehicle_time => $route->getAttribute('vehicleTime'), + }; + + my $e_fare = ( $route->findnodes($xp_fare) )[0]; + + if ($e_fare) { + $info->{ticket_type} = $e_fare->getAttribute('unitsAdult'); + $info->{fare_adult} = $e_fare->getAttribute('fareAdult'); + $info->{fare_child} = $e_fare->getAttribute('fareChild'); + $info->{ticket_text} = $e_fare->textContent; + } for my $e ( $route->findnodes($xp_route) ) { diff --git a/lib/Travel/Routing/DE/VRR/Route.pm b/lib/Travel/Routing/DE/VRR/Route.pm index 73bda07..a4f000b 100644 --- a/lib/Travel/Routing/DE/VRR/Route.pm +++ b/lib/Travel/Routing/DE/VRR/Route.pm @@ -4,10 +4,16 @@ use strict; use warnings; use 5.010; +use parent 'Class::Accessor'; + use Travel::Routing::DE::VRR::Route::Part; our $VERSION = '1.06'; +Travel::Routing::DE::VRR::Route->mk_ro_accessors( + qw(duration ticket_text ticket_type fare_adult fare_child vehicle_time) +); + sub new { my ( $obj, $info, @parts ) = @_; |