Class: CalendariumRomanum::Ordinalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/ordinalizer.rb

Overview

Knows how to produce localized ordinals

Class Method Summary collapse

Class Method Details

.english_ordinal(number) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/calendarium-romanum/ordinalizer.rb', line 23

def english_ordinal(number)
  modulo = number % 10
  modulo = 9 if number / 10 == 1

  case modulo
  when 1
    "#{number}st"
  when 2
    "#{number}nd"
  when 3
    "#{number}rd"
  else
    "#{number}th"
  end
end

.ordinal(number, locale: nil) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/calendarium-romanum/ordinalizer.rb', line 7

def ordinal(number, locale: nil)
  locale ||= I18n.locale

  case locale
  when :cs
    "#{number}."
  when :en
    english_ordinal(number)
  # when :it # TODO
  when :la, :it
    RomanNumerals.to_roman number
  else
    number
  end
end