Module: Ordinalize
- Included in:
- Numeric
- Defined in:
- lib/ordinalize.rb
Instance Method Summary collapse
- #conversions ⇒ Object
- #ordinalize ⇒ Object (also: #ordinalise)
- #split_dashes ⇒ Object
- #split_spaces ⇒ Object
Instance Method Details
#conversions ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ordinalize.rb', line 35 def conversions { "one" => "first", "two" => "second", "three" => "third", "four" => "fourth", "five" => "fifth", "six" => "sixth", "seven" => "seventh", "eight" => "eighth", "nine" => "ninth", "ten" => "tenth", "eleven" => "eleventh", "twelve" => "twelveth", } end |
#ordinalize ⇒ Object Also known as: ordinalise
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ordinalize.rb', line 7 def ordinalize humanized = self.humanize # 13-19 humanized += "th" if humanized =~ /teen$/ # 20, 30, 40, etc. humanized.gsub!(/ty$/, 'tieth') output = conversions[humanized] if conversions[humanized] output ||= split_dashes if split_dashes != "" output ||= split_spaces if split_spaces != "" output ||= humanized end |
#split_dashes ⇒ Object
23 24 25 26 27 |
# File 'lib/ordinalize.rb', line 23 def split_dashes parts = humanize.split("-") parts[-1] = conversions[parts.last] parts.join("-") end |
#split_spaces ⇒ Object
29 30 31 32 33 |
# File 'lib/ordinalize.rb', line 29 def split_spaces parts = humanize.split(" ") parts[-1] = conversions[parts.last] parts.join(" ") end |