namecase 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +39 -0
- data/doc/CVS/Entries +8 -0
- data/doc/CVS/Repository +1 -0
- data/doc/CVS/Root +1 -0
- data/doc/classes/CVS/Entries +6 -0
- data/doc/classes/CVS/Repository +1 -0
- data/doc/classes/CVS/Root +1 -0
- data/doc/classes/NameCase.html +158 -0
- data/doc/classes/NameCase.src/CVS/Entries +3 -0
- data/doc/classes/NameCase.src/CVS/Repository +1 -0
- data/doc/classes/NameCase.src/CVS/Root +1 -0
- data/doc/classes/NameCase.src/M000001.html +59 -0
- data/doc/classes/NameCase.src/M000002.html +18 -0
- data/doc/classes/String.html +159 -0
- data/doc/classes/String.src/CVS/Entries +3 -0
- data/doc/classes/String.src/CVS/Repository +1 -0
- data/doc/classes/String.src/CVS/Root +1 -0
- data/doc/classes/String.src/M000004.html +59 -0
- data/doc/classes/String.src/M000005.html +18 -0
- data/doc/classes/TestNameCase.html +167 -0
- data/doc/classes/TestNameCase.src/CVS/Entries +6 -0
- data/doc/classes/TestNameCase.src/CVS/Repository +1 -0
- data/doc/classes/TestNameCase.src/CVS/Root +1 -0
- data/doc/classes/TestNameCase.src/M000001.html +38 -0
- data/doc/classes/TestNameCase.src/M000002.html +20 -0
- data/doc/classes/TestNameCase.src/M000003.html +38 -0
- data/doc/classes/TestNameCase.src/M000004.html +21 -0
- data/doc/classes/TestNameCase.src/M000005.html +21 -0
- data/doc/created.rid +1 -0
- data/doc/files/CVS/Entries +3 -0
- data/doc/files/CVS/Repository +1 -0
- data/doc/files/CVS/Root +1 -0
- data/doc/files/README.html +162 -0
- data/doc/files/lib/CVS/Entries +2 -0
- data/doc/files/lib/CVS/Repository +1 -0
- data/doc/files/lib/CVS/Root +1 -0
- data/doc/files/lib/namecase_rb.html +101 -0
- data/doc/files/test/CVS/Entries +2 -0
- data/doc/files/test/CVS/Repository +1 -0
- data/doc/files/test/CVS/Root +1 -0
- data/doc/files/test/test_namecase_rb.html +109 -0
- data/doc/fr_class_index.html +28 -0
- data/doc/fr_file_index.html +28 -0
- data/doc/fr_method_index.html +31 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/CVS/Entries +2 -0
- data/lib/CVS/Repository +1 -0
- data/lib/CVS/Root +1 -0
- data/lib/namecase.rb +53 -0
- data/test/CVS/Entries +2 -0
- data/test/CVS/Repository +1 -0
- data/test/CVS/Root +1 -0
- data/test/test_namecase.rb +44 -0
- metadata +110 -0
data/lib/CVS/Entries
ADDED
data/lib/CVS/Repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
namecase/lib
|
data/lib/CVS/Root
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
:ext:aaronp@rubyforge.org:/var/cvs/namecase
|
data/lib/namecase.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class NameCase < String
|
2
|
+
|
3
|
+
# Returns a new +String+ with the contents properly namecased
|
4
|
+
def nc
|
5
|
+
localstring = self.downcase
|
6
|
+
localstring.gsub!(/\b\w/) { |first| first.upcase }
|
7
|
+
localstring.gsub!("\'\w\b") { |c| c.downcase } # Lowercase 's
|
8
|
+
|
9
|
+
if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/
|
10
|
+
localstring.gsub!(/\b(Ma?c)([A-Za-z]+)/) { |match| $1 + $2.capitalize }
|
11
|
+
|
12
|
+
# Now fix "Mac" exceptions
|
13
|
+
localstring.gsub!(/\bMacEvicius/, 'Macevicius')
|
14
|
+
localstring.gsub!(/\bMacHado/, 'Machado')
|
15
|
+
localstring.gsub!(/\bMacHar/, 'Machar')
|
16
|
+
localstring.gsub!(/\bMacHin/, 'Machin')
|
17
|
+
localstring.gsub!(/\bMacHlin/, 'Machlin')
|
18
|
+
localstring.gsub!(/\bMacIas/, 'Macias')
|
19
|
+
localstring.gsub!(/\bMacIulis/, 'Maciulis')
|
20
|
+
localstring.gsub!(/\bMacKie/, 'Mackie')
|
21
|
+
localstring.gsub!(/\bMacKle/, 'Mackle')
|
22
|
+
localstring.gsub!(/\bMacKlin/, 'Macklin')
|
23
|
+
localstring.gsub!(/\bMacQuarie/, 'Macquarie')
|
24
|
+
end
|
25
|
+
localstring.gsub!('Macmurdo','MacMurdo')
|
26
|
+
|
27
|
+
# Fixes for "son (daughter) of" etc
|
28
|
+
localstring.gsub!(/\bAl(?=\s+\w)/, 'al') # al Arabic or forename Al.
|
29
|
+
localstring.gsub!(/\bAp\b/, 'ap') # ap Welsh.
|
30
|
+
localstring.gsub!(/\bBen(?=\s+\w)/,'ben') # ben Hebrew or forename Ben.
|
31
|
+
localstring.gsub!(/\bDell([ae])\b/,'dell\1') # della and delle Italian.
|
32
|
+
localstring.gsub!(/\bD([aeiu])\b/,'d\1') # da, de, di Italian; du French.
|
33
|
+
localstring.gsub!(/\bDe([lr])\b/,'de\1') # del Italian; der Dutch/Flemish.
|
34
|
+
localstring.gsub!(/\bEl\b/,'el') # el Greek or El Spanish.
|
35
|
+
localstring.gsub!(/\bLa\b/,'la') # la French or La Spanish.
|
36
|
+
localstring.gsub!(/\bL([eo])\b/,'l\1') # lo Italian; le French.
|
37
|
+
localstring.gsub!(/\bVan(?=\s+\w)/,'van') # van German or forename Van.
|
38
|
+
localstring.gsub!(/\bVon\b/,'von') # von Dutch/Flemish
|
39
|
+
|
40
|
+
# Fix roman numeral names
|
41
|
+
localstring.gsub!(
|
42
|
+
/ \b ( (?: [Xx]{1,3} | [Xx][Ll] | [Ll][Xx]{0,3} )?
|
43
|
+
(?: [Ii]{1,3} | [Ii][VvXx] | [Vv][Ii]{0,3} )? ) \b /x
|
44
|
+
) { |match| match.upcase }
|
45
|
+
|
46
|
+
localstring
|
47
|
+
end
|
48
|
+
|
49
|
+
# Modifies _str_ in place and properly namecases the string.
|
50
|
+
def nc!
|
51
|
+
self.gsub!(self, self.nc)
|
52
|
+
end
|
53
|
+
end
|
data/test/CVS/Entries
ADDED
data/test/CVS/Repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
namecase/test
|
data/test/CVS/Root
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
:ext:aaronp@rubyforge.org:/var/cvs/namecase
|
@@ -0,0 +1,44 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'namecase'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestNameCase < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@proper_names = [
|
9
|
+
"Keith", "Leigh-Williams", "McCarthy",
|
10
|
+
"O'Callaghan", "St. John", "von Streit",
|
11
|
+
"van Dyke", "Van", "ap Llwyd Dafydd",
|
12
|
+
"al Fahd", "Al",
|
13
|
+
"el Grecco",
|
14
|
+
"ben Gurion", "Ben",
|
15
|
+
"da Vinci",
|
16
|
+
"di Caprio", "du Pont", "de Legate",
|
17
|
+
"del Crond", "der Sind", "van der Post",
|
18
|
+
"von Trapp", "la Poisson", "le Figaro",
|
19
|
+
"Mack Knife", "Dougal MacDonald",
|
20
|
+
# Mac exceptions
|
21
|
+
"Machin", "Machlin", "Machar",
|
22
|
+
"Mackle", "Macklin", "Mackie",
|
23
|
+
"Macquarie", "Machado", "Macevicius",
|
24
|
+
"Maciulis", "Macias", "MacMurdo",
|
25
|
+
# Roman numerals
|
26
|
+
"Henry VIII", "Louis III", "Louis XIV",
|
27
|
+
"Charles II", "Fred XLIX",
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_namecase
|
32
|
+
@proper_names.each do |name|
|
33
|
+
nc_name = NameCase.new(name)
|
34
|
+
assert_equal(name, nc_name.downcase.nc)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_namecase_modify
|
39
|
+
@proper_names.each do |name|
|
40
|
+
nc_name = NameCase.new(name)
|
41
|
+
assert_equal(name, nc_name.downcase.nc!)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: namecase
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2005-11-07
|
8
|
+
summary: "NameCase is a Ruby implementation of Lingua::EN::NameCase, a library for
|
9
|
+
converting strings to be properly cased."
|
10
|
+
require_paths:
|
11
|
+
- lib
|
12
|
+
email: aaronp@rubyforge.org
|
13
|
+
homepage: namecase.rubyforge.org
|
14
|
+
rubyforge_project: namecase
|
15
|
+
description:
|
16
|
+
autorequire: NameCase
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
-
|
23
|
+
- ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
authors:
|
29
|
+
- Aaron Patterson
|
30
|
+
files:
|
31
|
+
- test/CVS
|
32
|
+
- test/test_namecase.rb
|
33
|
+
- test/CVS/Entries
|
34
|
+
- test/CVS/Repository
|
35
|
+
- test/CVS/Root
|
36
|
+
- lib/CVS
|
37
|
+
- lib/namecase.rb
|
38
|
+
- lib/CVS/Entries
|
39
|
+
- lib/CVS/Repository
|
40
|
+
- lib/CVS/Root
|
41
|
+
- doc/classes
|
42
|
+
- doc/created.rid
|
43
|
+
- doc/CVS
|
44
|
+
- doc/files
|
45
|
+
- doc/fr_class_index.html
|
46
|
+
- doc/fr_file_index.html
|
47
|
+
- doc/fr_method_index.html
|
48
|
+
- doc/index.html
|
49
|
+
- doc/rdoc-style.css
|
50
|
+
- doc/classes/CVS
|
51
|
+
- doc/classes/NameCase.html
|
52
|
+
- doc/classes/NameCase.src
|
53
|
+
- doc/classes/String.html
|
54
|
+
- doc/classes/String.src
|
55
|
+
- doc/classes/TestNameCase.html
|
56
|
+
- doc/classes/TestNameCase.src
|
57
|
+
- doc/classes/CVS/Entries
|
58
|
+
- doc/classes/CVS/Repository
|
59
|
+
- doc/classes/CVS/Root
|
60
|
+
- doc/classes/NameCase.src/CVS
|
61
|
+
- doc/classes/NameCase.src/M000001.html
|
62
|
+
- doc/classes/NameCase.src/M000002.html
|
63
|
+
- doc/classes/NameCase.src/CVS/Entries
|
64
|
+
- doc/classes/NameCase.src/CVS/Repository
|
65
|
+
- doc/classes/NameCase.src/CVS/Root
|
66
|
+
- doc/classes/String.src/CVS
|
67
|
+
- doc/classes/String.src/M000004.html
|
68
|
+
- doc/classes/String.src/M000005.html
|
69
|
+
- doc/classes/String.src/CVS/Entries
|
70
|
+
- doc/classes/String.src/CVS/Repository
|
71
|
+
- doc/classes/String.src/CVS/Root
|
72
|
+
- doc/classes/TestNameCase.src/CVS
|
73
|
+
- doc/classes/TestNameCase.src/M000001.html
|
74
|
+
- doc/classes/TestNameCase.src/M000002.html
|
75
|
+
- doc/classes/TestNameCase.src/M000003.html
|
76
|
+
- doc/classes/TestNameCase.src/M000004.html
|
77
|
+
- doc/classes/TestNameCase.src/M000005.html
|
78
|
+
- doc/classes/TestNameCase.src/CVS/Entries
|
79
|
+
- doc/classes/TestNameCase.src/CVS/Repository
|
80
|
+
- doc/classes/TestNameCase.src/CVS/Root
|
81
|
+
- doc/CVS/Entries
|
82
|
+
- doc/CVS/Repository
|
83
|
+
- doc/CVS/Root
|
84
|
+
- doc/files/CVS
|
85
|
+
- doc/files/lib
|
86
|
+
- doc/files/README.html
|
87
|
+
- doc/files/test
|
88
|
+
- doc/files/CVS/Entries
|
89
|
+
- doc/files/CVS/Repository
|
90
|
+
- doc/files/CVS/Root
|
91
|
+
- doc/files/lib/CVS
|
92
|
+
- doc/files/lib/namecase_rb.html
|
93
|
+
- doc/files/lib/CVS/Entries
|
94
|
+
- doc/files/lib/CVS/Repository
|
95
|
+
- doc/files/lib/CVS/Root
|
96
|
+
- doc/files/test/CVS
|
97
|
+
- doc/files/test/test_namecase_rb.html
|
98
|
+
- doc/files/test/CVS/Entries
|
99
|
+
- doc/files/test/CVS/Repository
|
100
|
+
- doc/files/test/CVS/Root
|
101
|
+
- README
|
102
|
+
test_files:
|
103
|
+
- test/test_namecase.rb
|
104
|
+
rdoc_options: []
|
105
|
+
extra_rdoc_files:
|
106
|
+
- README
|
107
|
+
executables: []
|
108
|
+
extensions: []
|
109
|
+
requirements: []
|
110
|
+
dependencies: []
|