def ddc_transform(raw): """ Transform the ddc search field value :param str raw: :rtype: str """ m = re_range.match(raw) if m: raw = [m.group('start').strip(), m.group('end').strip()] normed = normalize_ddc_range(*raw) return '[%s TO %s]' % ( normed[0] or raw[0], normed[1] or raw[1]) elif raw.endswith('*'): return normalize_ddc_prefix(raw[:-1]) + '*' else: normed = normalize_ddc(raw.strip('"')) if normed: return normed[0] # if none of the transforms took return raw
def test_normalize_ddc_with_oclc_spec(raw_ddc, expected, name): assert normalize_ddc(raw_ddc) == expected
def test_noramlize_ddc(raw_ddc, expected, name): assert normalize_ddc(raw_ddc) == expected