public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
More inflector fixes #1608

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1699 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Tue Jul 05 00:44:46 -0700 2005
commit  f4c579e92e5d0787721ba958a571570c12563b11
tree    e0bfd18107e720a83efd1aebb92a5d58794308a5
parent  0e92f36d7506ebb7248d046e19299553edad6f53
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@
0
 
0
 * Fixed conflict with Glue gem #1606 [Rick Olson]
0
 
0
-* Added new rules to the Inflector to deal with more unusual plurals mouse/louse => mice/lice, information => information, ox => oxen, virus => viri, archive => archives #1571, #1583, #1490, #1599 [foamdino@gmail.com/others]
0
+* Added new rules to the Inflector to deal with more unusual plurals mouse/louse => mice/lice, information => information, ox => oxen, virus => viri, archive => archives #1571, #1583, #1490, #1599, #1608 [foamdino@gmail.com/others]
0
 
0
 * Fixed memory leak with Object#remove_subclasses_of, which inflicted a Rails application running in development mode with a ~20KB leak per request #1289 [c.r.mcgrath@gmail.com]
0
 
...
5
6
7
8
9
 
 
 
 
 
 
10
11
12
13
14
15
16
17
 
 
 
 
 
 
18
19
20
21
22
...
55
56
57
 
 
 
 
58
59
60
61
62
63
64
65
 
 
 
 
66
67
68
 
 
69
70
71
72
73
74
75
76
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
81
82
83
84
85
86
87
 
 
88
89
90
91
 
 
 
92
93
 
94
95
96
...
103
104
105
106
 
107
108
109
110
111
112
113
 
114
...
5
6
7
 
 
8
9
10
11
12
13
14
 
15
16
17
18
 
 
19
20
21
22
23
24
25
 
26
27
28
...
61
62
63
64
65
66
67
68
69
 
 
 
 
 
 
70
71
72
73
74
 
 
75
76
77
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
95
96
97
98
99
 
100
101
102
103
 
104
105
106
107
...
114
115
116
 
117
118
119
120
121
122
123
 
124
125
0
@@ -5,18 +5,24 @@ module Inflector
0
 
0
   def pluralize(word)
0
     result = word.to_s.dup
0
- plural_rules.each do |(rule, replacement)|
0
- break if result.gsub!(rule, replacement)
0
+
0
+ if uncountable_words.include?(result.downcase)
0
+ result
0
+ else
0
+ plural_rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
0
+ result
0
     end
0
- return result
0
   end
0
 
0
   def singularize(word)
0
     result = word.to_s.dup
0
- singular_rules.each do |(rule, replacement)|
0
- break if result.gsub!(rule, replacement)
0
+
0
+ if uncountable_words.include?(result.downcase)
0
+ result
0
+ else
0
+ singular_rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
0
+ result
0
     end
0
- return result
0
   end
0
 
0
   def camelize(lower_case_and_underscored_word)
0
@@ -55,42 +61,47 @@ module Inflector
0
   end
0
 
0
   private
0
+ def uncountable_words #:doc
0
+ %w( equipment information rice money species series fish )
0
+ end
0
+
0
     def plural_rules #:doc:
0
       [
0
- [/(fish)$/i, '\1\2'], # fish
0
- [/(information|equipment|money)$/i, '\1'], # plural nouns
0
- [/^(ox)$/i, '\1\2en'], # ox
0
- [/([m|l])ouse/i, '\1ice'], # mouse, louse
0
- [/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address
0
- [/(series)$/i, '\1\2'],
0
+ [/^(ox)$/i, '\1\2en'], # ox
0
+ [/([m|l])ouse$/i, '\1ice'], # mouse, louse
0
+ [/(matr|vert)ix|ex$/i, '\1ices'], # matrix, vertex, index
0
+ [/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address
0
         [/([^aeiouy]|qu)ies$/i, '\1y'],
0
- [/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency
0
- [/(hive)$/i, '\1s'], # archive, hive
0
+ [/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency
0
+ [/(hive)$/i, '\1s'], # archive, hive
0
         [/(?:([^f])fe|([lr])f)$/i, '\1\2ves'], # half, safe, wife
0
- [/sis$/i, 'ses'], # basis, diagnosis
0
- [/([ti])um$/i, '\1a'], # datum, medium
0
- [/(p)erson$/i, '\1\2eople'], # person, salesperson
0
- [/(m)an$/i, '\1\2en'], # man, woman, spokesman
0
- [/(c)hild$/i, '\1\2hildren'], # child
0
- [/(photo)$/i, '\1s'],
0
- [/(buffal|tomat)o$/i, '\1\2oes'], # buffalo, tomato
0
- [/(bu)s$/i, '\1\2ses'], # bus
0
- [/(alias)/i, '\1es'], # alias
0
- [/([octop|vir])us$/i, '\1i'], # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
0
- [/s$/i, 's'], # no change (compatibility)
0
+ [/sis$/i, 'ses'], # basis, diagnosis
0
+ [/([ti])um$/i, '\1a'], # datum, medium
0
+ [/(p)erson$/i, '\1eople'], # person, salesperson
0
+ [/(m)an$/i, '\1en'], # man, woman, spokesman
0
+ [/(c)hild$/i, '\1hildren'], # child
0
+ [/(buffal|tomat)o$/i, '\1\2oes'], # buffalo, tomato
0
+ [/(bu)s$/i, '\1\2ses'], # bus
0
+ [/(alias)/i, '\1es'], # alias
0
+ [/(octop|vir)us$/i, '\1i'], # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
0
+ [/(ax|cri|test)is$/i, '\1es'], # axis, crisis
0
+ [/s$/i, 's'], # no change (compatibility)
0
         [/$/, 's']
0
       ]
0
     end
0
 
0
     def singular_rules #:doc:
0
       [
0
- [/(f)ish$/i, '\1\2ish'],
0
+ [/(matr)ices$/i, '\1ix'],
0
+ [/(vert)ices$/i, '\1ex'],
0
         [/^(ox)en/i, '\1'],
0
         [/(alias)es$/i, '\1'],
0
         [/([octop|vir])i$/i, '\1us'],
0
- [/(o)es/i, '\1'],
0
+ [/(cris|ax|test)es$/i, '\1is'],
0
+ [/(shoe)s$/i, '\1'],
0
+ [/(o)es$/i, '\1'],
0
         [/(bus)es$/i, '\1'],
0
- [/([m|l])ice/i, '\1ouse'],
0
+ [/([m|l])ice$/i, '\1ouse'],
0
         [/(x|ch|ss|sh)es$/i, '\1'],
0
         [/(m)ovies$/i, '\1\2ovie'],
0
         [/(s)eries$/i, '\1\2eries'],
0
@@ -103,11 +114,11 @@ module Inflector
0
         [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis'],
0
         [/([ti])a$/i, '\1um'],
0
         [/(p)eople$/i, '\1\2erson'],
0
- [/(m)en$/i, '\1\2an'],
0
+ [/(m)en$/i, '\1an'],
0
         [/(s)tatus$/i, '\1\2tatus'],
0
         [/(c)hildren$/i, '\1\2hild'],
0
         [/(n)ews$/i, '\1\2ews'],
0
         [/s$/i, '']
0
       ]
0
     end
0
-end
0
+end
0
\ No newline at end of file
...
61
62
63
 
64
65
66
...
74
75
76
 
77
78
79
80
81
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
84
85
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
 
214
...
61
62
63
64
65
66
67
...
75
76
77
78
79
80
81
82
83
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...
214
215
216
 
 
 
 
 
 
 
 
 
 
 
 
 
217
218
0
@@ -61,6 +61,7 @@ class InflectorTest < Test::Unit::TestCase
0
     "news" => "news",
0
     
0
     "series" => "series",
0
+ "species" => "species",
0
 
0
     "perspective" => "perspectives",
0
     
0
@@ -74,12 +75,27 @@ class InflectorTest < Test::Unit::TestCase
0
     "equipment" => "equipment",
0
     "bus" => "buses",
0
     "mouse" => "mice",
0
+
0
     "louse" => "lice",
0
     "house" => "houses",
0
     "octopus" => "octopi",
0
     "virus" => "viri",
0
     "alias" => "aliases",
0
- "portfolio" => "portfolios"
0
+ "portfolio" => "portfolios",
0
+
0
+ "vertex" => "vertices",
0
+ "matrix" => "matrices",
0
+
0
+ "axis" => "axes",
0
+ "testis" => "testes",
0
+ "crisis" => "crises",
0
+
0
+ "rice" => "rice",
0
+ "shoe" => "shoes",
0
+
0
+ "horse" => "horses",
0
+ "prize" => "prizes",
0
+ "edge" => "edges"
0
   }
0
 
0
   CamelToUnderscore = {
0
@@ -198,16 +214,4 @@ class InflectorTest < Test::Unit::TestCase
0
     assert_equal InflectorTest, Inflector.constantize("InflectorTest")
0
     assert_raises(NameError) { Inflector.constantize("UnknownClass") }
0
   end
0
-
0
- # def test_staying_singular
0
- # for term in SingularToPlural.keys
0
- # assert_equal term, Inflector.singularize(term)
0
- # end
0
- # end
0
- #
0
- # def test_staying_plural
0
- # for term in SingularToPlural.values
0
- # assert_equal term, Inflector.singularize(term)
0
- # end
0
- # end
0
-end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.