Revision 68329cf0
Von Cem Aydin vor etwa 1 Jahr hinzugefügt
SL/Helper/QrBillParser.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use warnings; |
5 | 5 |
|
6 |
use SL::Helper::QrBillFunctions qw( |
|
7 |
get_street_name_from_address_line |
|
8 |
get_building_number_from_address_line |
|
9 |
get_postal_code_from_address_line |
|
10 |
get_town_name_from_address_line |
|
11 |
); |
|
12 |
|
|
6 | 13 |
use Rose::Object::MakeMethods::Generic( |
7 | 14 |
scalar => [ qw(is_valid error raw_data) ], |
8 | 15 |
'scalar --get_set_init' => [ qw(spec) ], |
... | ... | |
29 | 36 |
REGEX_TRAILER => qr{^EPD$}, |
30 | 37 |
REGEX_BILL_INFORMATION => qr{^.{0,140}$}, |
31 | 38 |
REGEX_ALTERNATIVE_SCHEME_PARAMETER => qr{^.{0,100}$}, |
32 |
REGEX_STREET_NAME_FROM_ADDRESS_LINE => qr{^(.*)\s+\d.*$}, |
|
33 |
REGEX_BUILDING_NUMBER_FROM_ADDRESS_LINE => qr{^.*\s+(\d+.*)$}, |
|
34 |
REGEX_POSTAL_CODE_FROM_ADDRESS_LINE => qr{^(\d+).*$}, |
|
35 |
REGEX_TOWN_FROM_ADDRESS_LINE => qr{^\d+\s(.*)$}, |
|
36 | 39 |
}; |
37 | 40 |
|
38 | 41 |
sub new { |
... | ... | |
74 | 77 |
|
75 | 78 |
sub get_creditor_field { |
76 | 79 |
my $self = shift; |
77 |
my ($structured_field, $extract_field, $extract_regex) = @_;
|
|
80 |
my ($structured_field, $extract_field, $extract_fn) = @_;
|
|
78 | 81 |
|
79 | 82 |
if ($self->{creditor}->{address_type} eq 'S') { |
80 | 83 |
return $self->{creditor}->{$structured_field}; |
81 | 84 |
} |
82 | 85 |
# extract |
83 |
$self->{creditor}->{$extract_field} =~ $extract_regex;
|
|
86 |
my $r = $extract_fn->($self->{creditor}->{$extract_field});
|
|
84 | 87 |
|
85 |
return $1 // '';
|
|
88 |
return $r // '';
|
|
86 | 89 |
} |
87 | 90 |
|
88 | 91 |
sub get_creditor_street_name { |
89 |
# extract street name from street_or_address_line_1 |
|
90 |
# the regex matches everything until the first digit |
|
91 | 92 |
return shift->get_creditor_field( |
92 | 93 |
'street_or_address_line_1', |
93 | 94 |
'street_or_address_line_1', |
94 |
REGEX_STREET_NAME_FROM_ADDRESS_LINE
|
|
95 |
\&get_street_name_from_address_line
|
|
95 | 96 |
); |
96 | 97 |
} |
97 | 98 |
|
98 | 99 |
sub get_creditor_building_number { |
99 |
# extract building number from street_or_address_line_1 |
|
100 |
# the regex matches the first digit and everything after |
|
101 | 100 |
return shift->get_creditor_field( |
102 | 101 |
'building_number_or_address_line_2', |
103 | 102 |
'street_or_address_line_1', |
104 |
REGEX_BUILDING_NUMBER_FROM_ADDRESS_LINE
|
|
103 |
\&get_building_number_from_address_line
|
|
105 | 104 |
); |
106 | 105 |
} |
107 | 106 |
|
108 | 107 |
sub get_creditor_post_code { |
109 |
# extract post code from building_number_or_address_line_2 |
|
110 |
# the regex matches the first digits |
|
111 | 108 |
return shift->get_creditor_field( |
112 | 109 |
'postal_code', |
113 | 110 |
'building_number_or_address_line_2', |
114 |
REGEX_POSTAL_CODE_FROM_ADDRESS_LINE
|
|
111 |
\&get_postal_code_from_address_line
|
|
115 | 112 |
); |
116 | 113 |
} |
117 | 114 |
|
118 | 115 |
sub get_creditor_town_name { |
119 |
# extract town name from building_number_or_address_line_2 |
|
120 |
# the regex matches everything after the first digits |
|
121 | 116 |
return shift->get_creditor_field( |
122 | 117 |
'town', |
123 | 118 |
'building_number_or_address_line_2', |
124 |
REGEX_TOWN_FROM_ADDRESS_LINE
|
|
119 |
\&get_town_name_from_address_line
|
|
125 | 120 |
); |
126 | 121 |
} |
127 | 122 |
|
Auch abrufbar als: Unified diff
Schweizer QR-Rechnung: Aufsplitten von kombinierten Adressfelder in Helferfunktionen ausgelagert