summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/HAFAS/Product.pm
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-03-27 10:27:01 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-03-27 10:27:01 +0100
commit830badd9e7413fc7fd4dc70e2e0219fa4642c954 (patch)
tree7c3357c3ecba14d41a1660f4658e5c0a778f2012 /lib/Travel/Status/DE/HAFAS/Product.pm
parentd45e7823ac80aa400c62e31ff5b3442804e41eba (diff)
Provide $journey->product->line_id in a line-colors compatible format
See https://github.com/Traewelling/line-colors/blob/main/line-colors.csv Closes #9
Diffstat (limited to 'lib/Travel/Status/DE/HAFAS/Product.pm')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Product.pm37
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Product.pm b/lib/Travel/Status/DE/HAFAS/Product.pm
index 5e45232..14cc018 100644
--- a/lib/Travel/Status/DE/HAFAS/Product.pm
+++ b/lib/Travel/Status/DE/HAFAS/Product.pm
@@ -11,19 +11,22 @@ use parent 'Class::Accessor';
our $VERSION = '5.05';
Travel::Status::DE::HAFAS::Product->mk_ro_accessors(
- qw(name type type_long class number line line_no operator)
-);
+ qw(name type type_long class number line line_id line_no operator));
# {{{ Constructor
sub new {
my ( $obj, %opt ) = @_;
- my $product = $opt{product};
- my $common = $opt{common};
- my $opL = $common->{opL};
+ my $product = $opt{product};
+ my $common = $opt{common};
+ my $opL = $common->{opL};
- my $class = $product->{cls};
+ # DB:
+ # catIn / catOutS eq "IXr" => "ICE X Regio"? regional tickets are generally accepted
+ # <= does not hold
+
+ my $class = $product->{cls};
my $name = $product->{addName} // $product->{name};
my $line_no = $product->{prodCtx}{line};
my $train_no = $product->{prodCtx}{num};
@@ -45,6 +48,11 @@ sub new {
$line_no = $product->{prodCtx}{matchId};
}
+ my $line_id;
+ if ( $product->{prodCtx}{lineId} ) {
+ $line_id = lc( $product->{prodCtx}{lineId} =~ s{_+}{-}gr );
+ }
+
my $operator;
if ( defined $product->{oprX} ) {
if ( my $opref = $opL->[ $product->{oprX} ] ) {
@@ -53,14 +61,15 @@ sub new {
}
my $ref = {
- name => $name,
- number => $train_no,
- line => $name,
- line_no => $line_no,
- type => $cat,
- type_long => $catlong,
- class => $class,
- operator => $operator,
+ name => $name,
+ number => $train_no,
+ line => $name,
+ line_id => $line_id,
+ line_no => $line_no,
+ type => $cat,
+ type_long => $catlong,
+ class => $class,
+ operator => $operator,
};
bless( $ref, $obj );