public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/ddollar/rails.git
Search Repo:
Added Inflector.humanize to turn attribute names like employee_salary into 
"Employee salary". Used by automated error reporting in AR.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@449 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Mon Jan 17 11:53:42 -0800 2005
commit  1b38c5523ecff17d4d78181db0fad1a74567c776
tree    1671abfe3831d19a6894d065dd7e6e7aa3c270cd
parent  ecfe77f38d21779af96bc9b8f876c15620151d6a
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* Added Inflector.humanize to turn attribute names like employee_salary into "Employee salary". Used by automated error reporting in AR.
0
+
0
 * Added availability of class inheritable attributes to the masses #477 [bitsweat]
0
 
0
     class Foo
...
27
28
29
 
 
 
 
30
31
32
...
27
28
29
30
31
32
33
34
35
36
0
@@ -27,6 +27,10 @@ module Inflector
0
     camel_cased_word.to_s.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
0
   end
0
 
0
+ def humanize(lower_case_and_underscored_word)
0
+ lower_case_and_underscored_word.to_s.gsub(/_/, " ").capitalize
0
+ end
0
+
0
   def demodulize(class_name_in_module)
0
     class_name_in_module.to_s.gsub(/^.*::/, '')
0
   end
...
65
66
67
 
 
 
 
 
68
69
70
...
120
121
122
 
 
 
 
 
 
123
124
...
65
66
67
68
69
70
71
72
73
74
75
...
125
126
127
128
129
130
131
132
133
134
135
0
@@ -65,6 +65,11 @@ class InflectorTest < Test::Unit::TestCase
0
     "PrimarySpokesman" => "primary_spokesmen",
0
     "NodeChild" => "node_children"
0
   }
0
+
0
+ UnderscoreToHuman = {
0
+ "employee_salary" => "Employee salary",
0
+ "underground" => "Underground"
0
+ }
0
 
0
   def test_pluralize
0
     SingularToPlural.each do |singular, plural|
0
@@ -120,4 +125,10 @@ class InflectorTest < Test::Unit::TestCase
0
       assert_equal(class_name, Inflector.classify(table_name))
0
     end
0
   end
0
+
0
+ def test_humanize
0
+ UnderscoreToHuman.each do |underscore, human|
0
+ assert_equal(human, Inflector.humanize(underscore))
0
+ end
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.