Module: Ordinals

Included in:
NumberTo
Defined in:
lib/modules/ordinals.rb

Overview

taken straight from activesupport/lib/active_support/inflector/methods.rb

Instance Method Summary collapse

Instance Method Details

#ordinal(number) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/modules/ordinals.rb', line 7

def ordinal(number)
  abs_number = number.to_i.abs
  if (11..13).include?(abs_number % 100)
    "th"
  else
    case abs_number % 10
      when 1; "st"
      when 2; "nd"
      when 3; "rd"
      else "th"
    end
  end
end

#to_ordinal(num) ⇒ Object



3
4
5
# File 'lib/modules/ordinals.rb', line 3

def to_ordinal(num)
  "#{num}#{ordinal(num)}"
end