Module: NumberWords
- Included in:
- NumberTo
- Defined in:
- lib/modules/number_words.rb
Defined Under Namespace
Classes: NumbersToWords
Constant Summary collapse
- DATA_FILE =
File.read(File.join(File.dirname(__FILE__), '../data/number_words.yml'))
- DAT =
YAML.load(DATA_FILE)
- WORDS =
DAT[:words]
- LARGE_NUMS =
DAT[:large_nums]
- ORDINALS =
DAT[:ordinals]
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
17 18 19 20 21 22 23 |
# File 'lib/modules/number_words.rb', line 17 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
25 26 27 |
# File 'lib/modules/number_words.rb', line 25 def ordinal_word(word) ORDINALS[word] || word += 'th' end |
#to_word_ordinal(num, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/modules/number_words.rb', line 12 def to_word_ordinal(num, = {}) text = NumbersToWords.new().to_words(num) change_last_word(text) end |
#to_words(num, options = {}) ⇒ Object
8 9 10 |
# File 'lib/modules/number_words.rb', line 8 def to_words(num, = {}) NumbersToWords.new().to_words(num) end |