This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNITS = Hash[(1..9).zip %w(um dois tres quatro cinco seis sete oito nove)] | |
SPECIAL = Hash[(11..19).zip %w(onze doze treze quatorze quinze dezesseis dezessete dezoito dezenove)] | |
DOZENS = Hash[(1..9).zip %w(dez vinte trinta quarenta cinquenta sessenta setenta oitenta noventa)] | |
def to_words(number) | |
return SPECIAL[number] if number.between?(11, 19) | |
dozens, units = number.divmod(10) | |
[DOZENS[dozens], UNITS[units]].compact.join(' e ') | |
end |