1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed Inflector.pluralize to handle capitalized words #932 [bitsweat]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@998 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-03-26 13:20:47 +00:00
parent 87b1d3834f
commit abfa14d825
3 changed files with 45 additions and 38 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Fixed Inflector.pluralize to handle capitalized words #932 [bitsweat]
* Added Object#suppress which allows you to make a saner choice around with exceptions to swallow #980. Example:
suppress(ZeroDivisionError) { 1/0 }

View file

@ -57,39 +57,39 @@ module Inflector
private
def plural_rules #:doc:
[
[/fish$/, 'fish'], # fish
[/(x|ch|ss|sh)$/, '\1es'], # search, switch, fix, box, process, address
[/series$/, '\1series'],
[/([^aeiouy]|qu)ies$/, '\1y'],
[/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency
[/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife
[/sis$/, 'ses'], # basis, diagnosis
[/([ti])um$/, '\1a'], # datum, medium
[/person$/, 'people'], # person, salesperson
[/man$/, 'men'], # man, woman, spokesman
[/child$/, 'children'], # child
[/s$/, 's'], # no change (compatibility)
[/(fish)$/i, '\1\2'], # fish
[/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address
[/(series)$/i, '\1\2'],
[/([^aeiouy]|qu)ies$/i, '\1y'],
[/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency
[/(?:([^f])fe|([lr])f)$/i, '\1\2ves'], # half, safe, wife
[/sis$/i, 'ses'], # basis, diagnosis
[/([ti])um$/i, '\1a'], # datum, medium
[/(p)erson$/i, '\1\2eople'], # person, salesperson
[/(m)an$/i, '\1\2en'], # man, woman, spokesman
[/(c)hild$/i, '\1\2hildren'], # child
[/s$/i, 's'], # no change (compatibility)
[/$/, 's']
]
end
def singular_rules #:doc:
[
[/fish$/, 'fish'],
[/(x|ch|ss|sh)es$/, '\1'],
[/movies$/, 'movie'],
[/series$/, 'series'],
[/([^aeiouy]|qu)ies$/, '\1y'],
[/([lr])ves$/, '\1f'],
[/([^f])ves$/, '\1fe'],
[/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
[/([ti])a$/, '\1um'],
[/people$/, 'person'],
[/men$/, 'man'],
[/status$/, 'status'],
[/children$/, 'child'],
[/news$/, 'news'],
[/s$/, '']
[/(f)ish$/i, '\1\2ish'],
[/(x|ch|ss|sh)es$/i, '\1'],
[/(m)ovies$/i, '\1\2ovie'],
[/(s)eries$/i, '\1\2eries'],
[/([^aeiouy]|qu)ies$/i, '\1y'],
[/([lr])ves$/i, '\1f'],
[/([^f])ves$/i, '\1fe'],
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis'],
[/([ti])a$/i, '\1um'],
[/(p)eople$/i, '\1\2erson'],
[/(m)en$/i, '\1\2an'],
[/(s)tatus$/i, '\1\2tatus'],
[/(c)hildren$/i, '\1\2hild'],
[/(n)ews$/i, '\1\2ews'],
[/s$/i, '']
]
end
end

View file

@ -17,9 +17,9 @@ class InflectorTest < Test::Unit::TestCase
"process" => "processes",
"address" => "addresses",
"case" => "cases",
"stack" => "stacks",
"wish" => "wishes",
"fish" => "fish",
"stack" => "stacks",
"wish" => "wishes",
"fish" => "fish",
"category" => "categories",
"query" => "queries",
@ -92,17 +92,22 @@ class InflectorTest < Test::Unit::TestCase
"underground" => "Underground"
}
def test_pluralize
SingularToPlural.each do |singular, plural|
assert_equal(plural, Inflector.pluralize(singular))
end
assert_equal("plurals", Inflector.pluralize("plurals"))
def test_pluralize_plurals
assert_equal "plurals", Inflector.pluralize("plurals")
assert_equal "Plurals", Inflector.pluralize("Plurals")
end
def test_singularize
SingularToPlural.each do |singular, plural|
SingularToPlural.each do |singular, plural|
define_method "test_pluralize_#{singular}" do
assert_equal(plural, Inflector.pluralize(singular))
assert_equal(plural.capitalize, Inflector.pluralize(singular.capitalize))
end
end
SingularToPlural.each do |singular, plural|
define_method "test_singularize_#{plural}" do
assert_equal(singular, Inflector.singularize(plural))
assert_equal(singular.capitalize, Inflector.singularize(plural.capitalize))
end
end