Skip to content

Commit

Permalink
ordinalize negative numbers patch
Browse files Browse the repository at this point in the history
Applied patch by Amir Manji
  #437 (comment)

Signed-off-by: Jason <jasonmichaelroth@gmail.com>
  • Loading branch information
jsnrth committed May 7, 2011
1 parent 7ec3f33 commit 3880ab0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/inflector/methods.rb
Expand Up @@ -136,10 +136,10 @@ def constantize(camel_cased_word) #:nodoc:
# ordinalize(1002) # => "1002nd"
# ordinalize(1003) # => "1003rd"
def ordinalize(number)
if (11..13).include?(number.to_i % 100)
if (11..13).include?(number.to_i.abs % 100)
"#{number}th"
else
case number.to_i % 10
case number.to_i.abs % 10
when 1; "#{number}st"
when 2; "#{number}nd"
when 3; "#{number}rd"
Expand Down
30 changes: 30 additions & 0 deletions activesupport/test/inflector_test_cases.rb
Expand Up @@ -215,6 +215,36 @@ module InflectorTestCases
}

OrdinalNumbers = {
"-1" => "-1st",
"-2" => "-2nd",
"-3" => "-3rd",
"-4" => "-4th",
"-5" => "-5th",
"-6" => "-6th",
"-7" => "-7th",
"-8" => "-8th",
"-9" => "-9th",
"-10" => "-10th",
"-11" => "-11th",
"-12" => "-12th",
"-13" => "-13th",
"-14" => "-14th",
"-20" => "-20th",
"-21" => "-21st",
"-22" => "-22nd",
"-23" => "-23rd",
"-24" => "-24th",
"-100" => "-100th",
"-101" => "-101st",
"-102" => "-102nd",
"-103" => "-103rd",
"-104" => "-104th",
"-110" => "-110th",
"-111" => "-111th",
"-112" => "-112th",
"-113" => "-113th",
"-1000" => "-1000th",
"-1001" => "-1001st",
"0" => "0th",
"1" => "1st",
"2" => "2nd",
Expand Down

0 comments on commit 3880ab0

Please sign in to comment.