Module: OrdinalizedFormatting

Included in:
Date, Time
Defined in:
lib/merb_helpers/ordinalize.rb

Overview

Time.now.to_ordinalized_s :long

> “February 28th, 2006 21:10”

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object



30
31
32
# File 'lib/merb_helpers/ordinalize.rb', line 30

def self.extended(obj)
  include Merb::Helpers::DateAndTime
end

Instance Method Details

#strftime_ordinalized(fmt, format = nil) ⇒ Object

Gives you a relative date in an attractive format

Parameters

format<String>

strftime string used to formatt a time/date object

locale<String, Symbol>

An optional value which can be used by localization plugins

Returns

String

Ordinalized time/date object

Examples

5.days.ago.strftime_ordinalized('%b %d, %Y')     # =>


51
52
53
# File 'lib/merb_helpers/ordinalize.rb', line 51

def strftime_ordinalized(fmt, format=nil)
  strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { |s| s.to_i.ordinalize }
end

#to_ordinalized_s(format = :default) ⇒ Object



34
35
36
37
38
# File 'lib/merb_helpers/ordinalize.rb', line 34

def to_ordinalized_s(format = :default)
  format = Merb::Helpers::DateAndTime.date_formats[format] 
  return self.to_s if format.nil?
  strftime_ordinalized(format)
end