Skip to content

Commit

Permalink
Agrega 'normalized_door_number_unit'.
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed May 31, 2019
1 parent 67ab1c0 commit f3be83a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions georef_ar_address/address_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ def normalized_door_number_value(self):
match = re.search(r'\d+', self._door_number_value)
return int(match.group(0)) if match else None

def normalized_door_number_unit(self):
"""Retorna la unidad de la altura de la dirección. Por el momento, las
unidades disponibles son:
- None: Altura sin unidad. Esto corresponde a alturas normales (número
de calle). Asociado a direcciones que utilizan "N", "N°", "Nro.",
etc.
- 'km': Kilómetros.
Returns:
None, str: Unidad normalizada de la altura.
"""
if not self._door_number_unit:
return None

if re.search(r'km|kil(o|ó)metro', self._door_number_unit,
re.IGNORECASE):
return 'km'

return None

@property
def type(self):
"""Getter para el atributo '_type'.
Expand Down
23 changes: 23 additions & 0 deletions tests/test_georef_ar_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,26 @@ def test_none_door_number_value(self):
'normalized_door_number_value()'."""
data = self.parser.parse('Leandro Alem S/N')
self.assertIsNone(data.normalized_door_number_value())


class DoorNumberUnitTest(unittest.TestCase):
def setUp(self):
self.parser = AddressParser()

def test_int_door_number_unit_none(self):
"""Una dirección con altura sin prefijo debería devolver None en
'normalized_door_number_unit()'."""
data = self.parser.parse('Callao 1231')
self.assertIsNone(data.normalized_door_number_unit())

def test_int_door_number_unit_none_n(self):
"""Una dirección con altura sin prefijo 'N' debería devolver None en
'normalized_door_number_unit()'."""
data = self.parser.parse('Callao N 1231')
self.assertIsNone(data.normalized_door_number_unit())

def test_int_door_number_unit_km(self):
"""Una dirección con altura sin prefijo 'KM.' debería devolver 'km' en
'normalized_door_number_unit()'."""
data = self.parser.parse('Ruta 33 KM. 33')
self.assertEqual(data.normalized_door_number_unit(), 'km')

0 comments on commit f3be83a

Please sign in to comment.