module EZTime
Public Class Methods
ordinal(number, include_cardinal=false)
click to toggle source
# File lib/eztime.rb, line 5 def self.ordinal(number, include_cardinal=false) # The following code was based on work found at: # http://www.bigbold.com/snippets/user/jswizard#post2368 # Returns the cardinal (number) and ordinal (st, nd, rd, th, etc.) # Pass include_cardinal as false to only return the ordinal cardinal = number.to_i.abs if (10...20).include?(cardinal) then include_cardinal ? cardinal.to_s << 'th' : 'th' else ord = %w{th st nd rd th th th th th th}[cardinal % 10] include_cardinal ? cardinal.to_s << ord : ord end end
Public Instance Methods
eztime(format_str)
click to toggle source
Formats the date/time according to the formatting string format_str The formatting string consists of any of the methods defined in EZTime
(such as meridian, ordinal, zhour, etc.) as well as any other methods available to the object class. The methods are named in the string by preceeded them with a single colon (:). Any characters not preceeded by a colon will be passed through directly.
Example
d = DateTime.civil(2003, 12, 20, 17, 30, 0) puts d.eztime(":day :nmonth :year at :hour12::minute::second :lmeridian") Output: 20 December 2003 at 5:30:00 pm
# File lib/eztime.rb, line 129 def eztime(format_str) EZTime::FormattedTime.new(self).format(format_str) end