Module: NumberWords
- Included in:
- NumberTo
- Defined in:
- lib/modules/number_words.rb
Defined Under Namespace
Classes: NumbersToWords
Constant Summary collapse
- WORDS =
{ '0' => 'zero', '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten', '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen', '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen', '18' => 'eighteen', '19' => 'nineteen', '20' => 'twenty', '30' => 'thirty', '40' => 'forty', '50' => 'fifty', '60' => 'sixty', '70' => 'seventy', '80' => 'eighty', '90' => 'ninety' }
- LARGE_NUMS =
{ 1 => 'thousand', 2 => 'million', 3 => 'billion', 4 => 'trillion' }
- ORDINALS =
{ 'one' => 'first', 'two' => 'second', 'three' => 'third', 'four' => 'fourth', 'five' => 'fifth', 'six' => 'sixth', 'seven' => 'seventh', 'eight' => 'eighth', 'nine' => 'ninth', 'One' => 'First', 'Two' => 'Second', 'Three' => 'Third', 'Four' => 'Fourth', 'Five' => 'Fifth', 'Six' => 'Sixth', 'Seven' => 'Seventh', 'Eight' => 'Eighth', 'Nine' => 'Ninth' }
Instance Method Summary collapse
- #change_last_word(text) ⇒ Object
- #ordinal_word(word) ⇒ Object
- #to_word_ordinal(num, options = {}) ⇒ Object
- #to_words(num, options = {}) ⇒ Object
Instance Method Details
#change_last_word(text) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/modules/number_words.rb', line 69 def change_last_word(text) words = text.split(/(\W)/) last = words[words.size - 1] new_last = ordinal_word(last) words[words.size - 1] = new_last words.join end |
#ordinal_word(word) ⇒ Object
77 78 79 |
# File 'lib/modules/number_words.rb', line 77 def ordinal_word(word) ORDINALS[word] || word += 'th' end |
#to_word_ordinal(num, options = {}) ⇒ Object
64 65 66 67 |
# File 'lib/modules/number_words.rb', line 64 def to_word_ordinal(num, = {}) text = NumbersToWords.new(num, ).to_words change_last_word(text) end |
#to_words(num, options = {}) ⇒ Object
60 61 62 |
# File 'lib/modules/number_words.rb', line 60 def to_words(num, = {}) NumbersToWords.new(num, ).to_words end |