lib/active_support/inflector.rb in activesupport-1.4.4 vs lib/active_support/inflector.rb in activesupport-2.0.0

- old
+ new

@@ -45,12 +45,19 @@ # # Examples: # irregular 'octopus', 'octopi' # irregular 'person', 'people' def irregular(singular, plural) - plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) - singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + if singular[0,1].upcase == plural[0,1].upcase + plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) + singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + else + plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1]) + plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1]) + singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1]) + singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1]) + end end # Add uncountable words that shouldn't be attempted inflected. # # Examples: @@ -97,11 +104,11 @@ # "the blue mailman".pluralize #=> "the blue mailmen" # "CamelOctopus".pluralize #=> "CamelOctopi" def pluralize(word) result = word.to_s.dup - if inflections.uncountables.include?(result.downcase) + if word.empty? || inflections.uncountables.include?(result.downcase) result else inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } result end @@ -261,12 +268,12 @@ def ordinalize(number) if (11..13).include?(number.to_i % 100) "#{number}th" else case number.to_i % 10 - when 1: "#{number}st" - when 2: "#{number}nd" - when 3: "#{number}rd" + when 1; "#{number}st" + when 2; "#{number}nd" + when 3; "#{number}rd" else "#{number}th" end end end end