Parent

Stamp::Emitters::Ordinal

Attributes

field[R]

Public Class Methods

new(field) click to toggle source

@param [field] the field to be formatted (e.g. :month, :year)

# File lib/stamp/emitters/ordinal.rb, line 7
def initialize(field)
  @field = field
end

Public Instance Methods

format(target) click to toggle source
# File lib/stamp/emitters/ordinal.rb, line 11
def format(target)
  ordinalize(target.send(field))
end
ordinalize(number) click to toggle source

Cribbed from ActiveSupport::Inflector github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb

# File lib/stamp/emitters/ordinal.rb, line 17
def ordinalize(number)
  number.to_s + if (11..13).include?(number % 100)
    'th'
  else
    case number % 10
      when 1; 'st'
      when 2; 'nd'
      when 3; 'rd'
      else    'th'
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.