Newer
Older
Birte Kristina Friesel
committed
package Travel::Status::DE::HAFAS::Product;
# vim:foldmethod=marker
use strict;
use warnings;
use 5.014;
use parent 'Class::Accessor';
our $VERSION = '5.05';
Travel::Status::DE::HAFAS::Product->mk_ro_accessors(
qw(class line_id line_no name number type type_long operator));
Birte Kristina Friesel
committed
# {{{ Constructor
sub new {
my ( $obj, %opt ) = @_;
Birte Kristina Friesel
committed
my $product = $opt{product};
my $common = $opt{common};
my $opL = $common->{opL};
Birte Kristina Friesel
committed
Birte Kristina Friesel
committed
# DB:
# catIn / catOutS eq "IXr" => "ICE X Regio"? regional tickets are generally accepted
# <= does not hold
my $class = $product->{cls};
Birte Kristina Friesel
committed
my $name = $product->{addName} // $product->{name};
my $line_no = $product->{prodCtx}{line};
my $train_no = $product->{prodCtx}{num};
my $cat = $product->{prodCtx}{catOut};
my $catlong = $product->{prodCtx}{catOutL};
# ÖBB, you so silly
if ( $name and $name =~ m{Zug-Nr} and $product->{nameS} ) {
$name = $product->{nameS};
}
Birte Kristina Friesel
committed
if ( $name and $cat and $name eq $cat and $product->{nameS} ) {
$name .= ' ' . $product->{nameS};
}
Birte Kristina Friesel
committed
if ( defined $train_no and not $train_no ) {
$train_no = undef;
}
Birte Kristina Friesel
committed
if (
not defined $line_no
and defined $product->{prodCtx}{matchId}
and
( not defined $train_no or $product->{prodCtx}{matchId} ne $train_no )
)
{
$line_no = $product->{prodCtx}{matchId};
}
Birte Kristina Friesel
committed
my $line_id;
if ( $product->{prodCtx}{lineId} ) {
$line_id = lc( $product->{prodCtx}{lineId} =~ s{_+}{-}gr );
}
Birte Kristina Friesel
committed
my $operator;
if ( defined $product->{oprX} ) {
if ( my $opref = $opL->[ $product->{oprX} ] ) {
$operator = $opref->{name};
}
}
my $ref = {
Birte Kristina Friesel
committed
name => $name,
number => $train_no,
line_id => $line_id,
line_no => $line_no,
type => $cat,
type_long => $catlong,
class => $class,
operator => $operator,
Birte Kristina Friesel
committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
};
bless( $ref, $obj );
return $ref;
}
# }}}
sub TO_JSON {
my ($self) = @_;
return { %{$self} };
}
1;
__END__
=head1 NAME
Travel::Status::DE::HAFAS::Product - Information about a HAFAS product
associated with a journey.
=head1 SYNOPSIS
=head1 VERSION
version 5.05
=head1 DESCRIPTION
Travel::Status::DE::HAFAS::Product describes a product (e.g. train or bus)
associated with a Travel::Status::DE::HAFAS::Journey(3pm) or one of its
stops.
=head1 METHODS
=head2 ACCESSORS
=over
=item $product->class
An integer identifying the the mode of transport class. Semantics depend on
backend See Travel::Status::DE::HAFAS(3pm)'s C<< $hafas->get_active_service >>
method.
Birte Kristina Friesel
committed
=item $product->line_id
Birte Kristina Friesel
committed
Line identifier, or undef if it is unknown.
This is a backend-specific identifier, e.g. "7-vrr010-17" for VRR U17.
The format is compatible with L<https://github.com/Traewelling/line-colors>.
Birte Kristina Friesel
committed
=item $product->line_no
Line number, or undef if it is unknown.
Birte Kristina Friesel
committed
The line identifier may be a single number such as "11" (underground train
line U 11), a single word (e.g. "AIR") or a combination (e.g. "SB16").
May also provide line numbers of IC/ICE services.
=item $product->name
Trip or line name, either in a format like "Bus SB16" (Bus line
SB16), "RE 42" (RegionalExpress train 42) or "IC 2901" (InterCity train 2901,
no line information). May contain extraneous whitespace characters. Note that
this accessor does not return line information for DB IC/ICE/EC services, even
if it is available. Use B<line_no> for those.
Birte Kristina Friesel
committed
=item $product->number
Trip number (e.g. train number), or undef if it is unknown.
=item $product->type
Type of this product, e.g. "S" for S-Bahn, "RE" for Regional Express
or "STR" for tram / StraE<szlig>enbahn.
=item $product->type_long
Long type of this product, e.g. "S-Bahn" or "Regional-Express".
Birte Kristina Friesel
committed
=item $product->operator
The operator responsible for this product. Returns undef
Birte Kristina Friesel
committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
if the backend does not provide an operator.
=back
=head1 DIAGNOSTICS
None.
=head1 DEPENDENCIES
=over
=item Class::Accessor(3pm)
=back
=head1 BUGS AND LIMITATIONS
None known.
=head1 SEE ALSO
Travel::Status::DE::HAFAS(3pm).
=head1 AUTHOR
Copyright (C) 2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
=head1 LICENSE
This module is licensed under the same terms as Perl itself.