From fd7e51e949f6525e98d4df24f7fee5f1a1167891 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 28 Feb 2020 12:00:01 +0100 Subject: [PATCH] UNECRecommendation20: Mapping von Einheitsnamen auf Codes --- SL/Helper/UNECERecommendation20.pm | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 SL/Helper/UNECERecommendation20.pm diff --git a/SL/Helper/UNECERecommendation20.pm b/SL/Helper/UNECERecommendation20.pm new file mode 100644 index 000000000..3b77428c4 --- /dev/null +++ b/SL/Helper/UNECERecommendation20.pm @@ -0,0 +1,56 @@ +package SL::Helper::UNECERecommendation20; + +use strict; +use warnings; +use utf8; + +use Exporter qw(import); +our @EXPORT_OK = qw(map_name_to_alpha_2_code); + +use List::Util qw(first); + +my @mappings = ( + # areas + [ 'MTK', qr{^(?:m²|qm|quadrat *meter|quadrat *metre)$}i ], + + # distances + [ 'CMT', qr{^(?:cm|centi *meter|centi *metre)$}i ], + [ 'MTR', qr{^(?:m|meter|metre)$}i ], + [ 'KMT', qr{^(?:km|kilo *meter|kilo *metre)$}i ], + + # durations + [ 'SEC', qr{^(?:s|sec|second|sek|sekunde)$}i ], + [ 'MIN', qr{^min(?:ute)?$}i ], + [ 'MON', qr{^mon(?:th|at)?$}i ], + [ 'HUR', qr{^(?:h(?:our)?|std(?:unde)?)$}i ], + [ 'DAY', qr{^(?:day|tag)$}i ], + + # mass + [ 'MGM', qr{^(?:mg|milli *gramm?)$}i ], + [ 'GRM', qr{^(?:g|gramm?)$}i ], + [ 'KGM', qr{^(?:kg|kilo *gramm?)$}i ], + [ 'KTN', qr{^(?:t|tonne|kilo *tonne)$}i ], + + # volumes + [ 'MLT', qr{^(?:ml|milli *liter|milli *litre)$}i ], + [ 'LTR', qr{^(?:l|liter|litre)$}i ], + + # miscellaneous + [ 'C62', qr{^(?:stck|stück|pieces?|pc|psch|pauschal)$}i ], +); + +sub map_name_to_code { + my ($unit) = @_; + + return undef if ($unit // '') eq ''; + + my $code = first { $unit =~ $_->[1] } @mappings; + return $code->[0] if $code; + + no warnings 'once'; + $::lxdebug->message(LXDebug::WARN(), "UNECERecommendation20::map_name_code: no mapping found for '$unit'"); + + return undef; +} + +1; -- 2.20.1