Module: L10n::Inflections

Defined in:
lib/l10n/inflections.rb

Instance Method Summary collapse

Instance Method Details

#ordinal(number) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/l10n/inflections.rb', line 8

def ordinal(number)
  abs_number = number.to_i.abs

  key = if (11..13).include?(abs_number % 100)
    :other
  else
    case abs_number % 10
      when 1; :first
      when 2; :second
      when 3; :third
      else    :other
    end
  end
  I18n.t("i18n.inflections.ordinals.#{key}")
end

#ordinalize(number) ⇒ Object



4
5
6
# File 'lib/l10n/inflections.rb', line 4

def ordinalize(number)
  "#{number}#{ordinal(number)}"
end