Skip to content

Commit

Permalink
Minor cleanup and comment about using the assistance instead of my cu…
Browse files Browse the repository at this point in the history
…stom extensions...
  • Loading branch information
Chris Van Pelt authored and Chris Van Pelt committed Mar 13, 2008
1 parent e3c91da commit 152d325
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
1 change: 0 additions & 1 deletion merb_helpers/lib/merb_helpers.rb
Expand Up @@ -9,7 +9,6 @@ def self.load_helpers(helpers = HELPERS_FILES)
end

def self.load
puts "Loading.. #{Merb::Plugins.config[:merb_helpers].inspect}"
if Merb::Plugins.config[:merb_helpers]
config = Merb::Plugins.config[:merb_helpers]
raise "With and Without options cannot be used with merb_helpers plugin configuration" if config[:with] && config[:without]
Expand Down
51 changes: 26 additions & 25 deletions merb_helpers/lib/merb_helpers/date_time_helpers.rb
Expand Up @@ -26,6 +26,32 @@ def since(time = ::Time.now)
alias :from_now :since
end

class Integer
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
# Examples
# 1.ordinalize # => "1st"
# 2.ordinalize # => "2nd"
# 1002.ordinalize # => "1002nd"
# 1003.ordinalize # => "1003rd"
def ordinalize
if (11..13).include?(self % 100)
"#{self}th"
else
case self % 10
when 1; "#{self}st"
when 2; "#{self}nd"
when 3; "#{self}rd"
else "#{self}th"
end
end
end
end

Numeric.send :include, TimeDSL
# Everything above here has pretty much been implemented in the assistance gem...

# Time.now.to_ordinalized_s :long
# => "February 28th, 2006 21:10"
module OrdinalizedFormatting
Expand Down Expand Up @@ -67,31 +93,6 @@ class Time
def to_time; self; end
end

class Integer
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
# Examples
# 1.ordinalize # => "1st"
# 2.ordinalize # => "2nd"
# 1002.ordinalize # => "1002nd"
# 1003.ordinalize # => "1003rd"
def ordinalize
if (11..13).include?(self % 100)
"#{self}th"
else
case self % 10
when 1; "#{self}st"
when 2; "#{self}nd"
when 3; "#{self}rd"
else "#{self}th"
end
end
end
end

Numeric.send :include, TimeDSL

module Merb
module Helpers
# Provides a number of methods for displaying and dealing with dates and times
Expand Down

0 comments on commit 152d325

Please sign in to comment.