Revision fd7e51e9
Von Moritz Bunkus vor fast 5 Jahren hinzugefügt
SL/Helper/UNECERecommendation20.pm | ||
---|---|---|
1 |
package SL::Helper::UNECERecommendation20; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
use utf8; |
|
6 |
|
|
7 |
use Exporter qw(import); |
|
8 |
our @EXPORT_OK = qw(map_name_to_alpha_2_code); |
|
9 |
|
|
10 |
use List::Util qw(first); |
|
11 |
|
|
12 |
my @mappings = ( |
|
13 |
# areas |
|
14 |
[ 'MTK', qr{^(?:m²|qm|quadrat *meter|quadrat *metre)$}i ], |
|
15 |
|
|
16 |
# distances |
|
17 |
[ 'CMT', qr{^(?:cm|centi *meter|centi *metre)$}i ], |
|
18 |
[ 'MTR', qr{^(?:m|meter|metre)$}i ], |
|
19 |
[ 'KMT', qr{^(?:km|kilo *meter|kilo *metre)$}i ], |
|
20 |
|
|
21 |
# durations |
|
22 |
[ 'SEC', qr{^(?:s|sec|second|sek|sekunde)$}i ], |
|
23 |
[ 'MIN', qr{^min(?:ute)?$}i ], |
|
24 |
[ 'MON', qr{^mon(?:th|at)?$}i ], |
|
25 |
[ 'HUR', qr{^(?:h(?:our)?|std(?:unde)?)$}i ], |
|
26 |
[ 'DAY', qr{^(?:day|tag)$}i ], |
|
27 |
|
|
28 |
# mass |
|
29 |
[ 'MGM', qr{^(?:mg|milli *gramm?)$}i ], |
|
30 |
[ 'GRM', qr{^(?:g|gramm?)$}i ], |
|
31 |
[ 'KGM', qr{^(?:kg|kilo *gramm?)$}i ], |
|
32 |
[ 'KTN', qr{^(?:t|tonne|kilo *tonne)$}i ], |
|
33 |
|
|
34 |
# volumes |
|
35 |
[ 'MLT', qr{^(?:ml|milli *liter|milli *litre)$}i ], |
|
36 |
[ 'LTR', qr{^(?:l|liter|litre)$}i ], |
|
37 |
|
|
38 |
# miscellaneous |
|
39 |
[ 'C62', qr{^(?:stck|stück|pieces?|pc|psch|pauschal)$}i ], |
|
40 |
); |
|
41 |
|
|
42 |
sub map_name_to_code { |
|
43 |
my ($unit) = @_; |
|
44 |
|
|
45 |
return undef if ($unit // '') eq ''; |
|
46 |
|
|
47 |
my $code = first { $unit =~ $_->[1] } @mappings; |
|
48 |
return $code->[0] if $code; |
|
49 |
|
|
50 |
no warnings 'once'; |
|
51 |
$::lxdebug->message(LXDebug::WARN(), "UNECERecommendation20::map_name_code: no mapping found for '$unit'"); |
|
52 |
|
|
53 |
return undef; |
|
54 |
} |
|
55 |
|
|
56 |
1; |
Auch abrufbar als: Unified diff
UNECRecommendation20: Mapping von Einheitsnamen auf Codes