diff --git a/num2words/lang_IT.py b/num2words/lang_IT.py index a46a29c..00dfebf 100644 --- a/num2words/lang_IT.py +++ b/num2words/lang_IT.py @@ -196,9 +196,22 @@ class Num2Word_IT(object): pass def to_ordinal(self,value): - raise NotImplementedError() + if 0 <= value <= 10: + return ["primo", "secondo", "terzo", "quarto", "quinto", "sesto", "settimo", "ottavo", "nono", "decimo"][value - 1] + else: + as_word = self._toWords(value) + if as_word.endswith("dici"): + return re.sub("dici$", "dicesimo", as_word) + elif as_word.endswith("to"): + return re.sub("to$", "tesimo", as_word) + elif as_word.endswith("ta"): + return re.sub("ta$", "tesimo", as_word) + else: + return as_word + "simo" + n2w = Num2Word_IT() to_card = n2w.to_cardinal to_ord = n2w.to_ordinal to_ordnum = n2w.to_ordinal_num + diff --git a/tests/test_it.py b/tests/test_it.py index 07cd3a2..57bf646 100644 --- a/tests/test_it.py +++ b/tests/test_it.py @@ -35,6 +35,7 @@ class Num2WordsITTest(TestCase): (20,'venti'), (21,'ventuno'), (26,'ventisei'), + (28,'ventotto'), (30,'trenta'), (31,'trentuno'), (40,'quaranta'), @@ -80,3 +81,16 @@ class Num2WordsITTest(TestCase): for test in test_cases: self.assertEqual(num2words(test[0], lang='it'), test[1]) + def test_ordinal(self): + + test_cases = ( + (1,'primo'), + (8,'ottavo'), + (12,'dodicesimo'), + (14,'quattordicesimo'), + (28,'ventottesimo'), + (100,'centesimo'), + ) + + for test in test_cases: + self.assertEqual(num2words(test[0], lang='it', ordinal=True), test[1])