namecase 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/Gemfile +2 -0
- data/Manifest.txt +3 -1
- data/README.md +39 -0
- data/Rakefile +7 -3
- data/lib/namecase.rb +54 -32
- data/namecase.gemspec +39 -0
- data/test/test_namecase.rb +12 -14
- metadata +80 -46
- data/README.txt +0 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: edf1f1eb5ee71d6065f9b049c27919e030610c82
|
4
|
+
data.tar.gz: 692ccc2c2193cc8b89398db68dc76793bd82d64e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9db51017ca6b45a064ecfda0560a0abff55a8a3576688687b934304a5eba7925869f91c2ca49898d78d3f4bdecd77ec3bb9532362ff24f2ea3f1a30ce6b7ae43
|
7
|
+
data.tar.gz: 564562455858eebda4a8f084bc063042c0fd786dddc0082718a62a48d6c4546729f71a60745e2381332d1bcc5d1f9d45d8f9e3658418a85b0a3fe7de6f63df30
|
data/.gemtest
ADDED
File without changes
|
data/Gemfile
ADDED
data/Manifest.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# [NameCase](http://namecase.rubyforge.org/)
|
2
|
+
|
3
|
+
http://namecase.rubyforge.org/
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
NameCase is a Ruby implementation of `Lingua::EN::NameCase`, a library for
|
8
|
+
converting strings to be properly cased. This is good for converting
|
9
|
+
denormalized data to human friendly data.
|
10
|
+
|
11
|
+
## Example Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
NameCase("RON BURGUNDY") # => Ron Burgundy
|
15
|
+
NameCase("MCDONALDS") # => McDonalds
|
16
|
+
```
|
17
|
+
|
18
|
+
## Acknowledgements
|
19
|
+
|
20
|
+
This library is a port of the Perl library, and owes most of its functionality
|
21
|
+
to the [Perl version by Mark Summerfield](https://metacpan.org/release/SUMMER/Lingua-EN-NameCase-1.12). Any bugs in the Ruby port are my
|
22
|
+
fault.
|
23
|
+
|
24
|
+
## Author
|
25
|
+
|
26
|
+
Original Version:
|
27
|
+
Copyright (c) Mark Summerfield 1998-2002.
|
28
|
+
<summer@perlpress.com>
|
29
|
+
All Rights Reserved
|
30
|
+
|
31
|
+
Ruby Version:
|
32
|
+
Copyright (c) Aaron Patterson 2006
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
NameCase is distributed under the GPL license. Please see the LICENSE file.
|
37
|
+
|
38
|
+
|
39
|
+
[2]: https://metacpan.org/release/SUMMER/Lingua-EN-NameCase-1.12
|
data/Rakefile
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'hoe'
|
3
|
-
require './lib/namecase.rb'
|
4
3
|
|
5
|
-
Hoe.
|
6
|
-
|
4
|
+
Hoe.plugin :doofus, :git, :gemspec
|
5
|
+
|
6
|
+
Hoe.spec('namecase') do |p|
|
7
|
+
self.readme_file = 'README.md'
|
8
|
+
developer('Aaron Patterson', 'aaronp@rubyforge.org')
|
9
|
+
license 'GPL'
|
10
|
+
extra_dev_deps << ['minitest', '~> 4.0']
|
7
11
|
end
|
data/lib/namecase.rb
CHANGED
@@ -1,42 +1,65 @@
|
|
1
|
-
|
2
|
-
VERSION = '
|
1
|
+
module NameCase
|
2
|
+
VERSION = '2.0.0'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
# Returns a new +String+ with the contents properly namecased
|
5
|
+
def nc(options = {})
|
6
|
+
NameCase.nc self, options
|
8
7
|
end
|
9
8
|
|
10
|
-
#
|
11
|
-
def nc
|
12
|
-
|
9
|
+
# Modifies _str_ in place and properly namecases the string.
|
10
|
+
def nc!(options = {})
|
11
|
+
NameCase.nc! self, options
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.nc! str, options = {}
|
15
|
+
str.replace NameCase.nc(str, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.nc str, options = {}
|
19
|
+
options = { :lazy => true, :irish => true }.merge options
|
20
|
+
|
21
|
+
# Skip if string is mixed case
|
22
|
+
if options[:lazy]
|
23
|
+
first_letter_lower = str[0] == str.downcase[0]
|
24
|
+
all_lower_or_upper = (str.downcase == str || str.upcase == str)
|
25
|
+
|
26
|
+
return str unless first_letter_lower || all_lower_or_upper
|
27
|
+
end
|
28
|
+
|
29
|
+
localstring = str.downcase
|
13
30
|
localstring.gsub!(/\b\w/) { |first| first.upcase }
|
14
31
|
localstring.gsub!(/\'\w\b/) { |c| c.downcase } # Lowercase 's
|
15
32
|
|
16
|
-
if
|
17
|
-
localstring
|
33
|
+
if options[:irish]
|
34
|
+
if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/
|
35
|
+
match = localstring.match(/\b(Ma?c)([A-Za-z]+)/)
|
36
|
+
localstring.gsub!(/\bMa?c[A-Za-z]+/) { match[1] + match[2].capitalize }
|
18
37
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
# Now fix "Mac" exceptions
|
39
|
+
localstring.gsub!(/\bMacEdo/, 'Macedo')
|
40
|
+
localstring.gsub!(/\bMacEvicius/, 'Macevicius')
|
41
|
+
localstring.gsub!(/\bMacHado/, 'Machado')
|
42
|
+
localstring.gsub!(/\bMacHar/, 'Machar')
|
43
|
+
localstring.gsub!(/\bMacHin/, 'Machin')
|
44
|
+
localstring.gsub!(/\bMacHlin/, 'Machlin')
|
45
|
+
localstring.gsub!(/\bMacIas/, 'Macias')
|
46
|
+
localstring.gsub!(/\bMacIulis/, 'Maciulis')
|
47
|
+
localstring.gsub!(/\bMacKie/, 'Mackie')
|
48
|
+
localstring.gsub!(/\bMacKle/, 'Mackle')
|
49
|
+
localstring.gsub!(/\bMacKlin/, 'Macklin')
|
50
|
+
localstring.gsub!(/\bMacKmin/, 'Mackmin')
|
51
|
+
localstring.gsub!(/\bMacQuarie/, 'Macquarie')
|
52
|
+
end
|
53
|
+
localstring.gsub!('Macmurdo','MacMurdo')
|
31
54
|
end
|
32
|
-
localstring.gsub!('Macmurdo','MacMurdo')
|
33
55
|
|
34
56
|
# Fixes for "son (daughter) of" etc
|
35
57
|
localstring.gsub!(/\bAl(?=\s+\w)/, 'al') # al Arabic or forename Al.
|
36
58
|
localstring.gsub!(/\bAp\b/, 'ap') # ap Welsh.
|
37
59
|
localstring.gsub!(/\bBen(?=\s+\w)/,'ben') # ben Hebrew or forename Ben.
|
38
60
|
localstring.gsub!(/\bDell([ae])\b/,'dell\1') # della and delle Italian.
|
39
|
-
localstring.gsub!(/\bD([
|
61
|
+
localstring.gsub!(/\bD([aeiou])\b/,'d\1') # da, de, di Italian; du French; do Brasil
|
62
|
+
localstring.gsub!(/\bD([ao]s)\b/,'d\1') # das, dos Brasileiros
|
40
63
|
localstring.gsub!(/\bDe([lr])\b/,'de\1') # del Italian; der Dutch/Flemish.
|
41
64
|
localstring.gsub!(/\bEl\b/,'el') # el Greek or El Spanish.
|
42
65
|
localstring.gsub!(/\bLa\b/,'la') # la French or La Spanish.
|
@@ -48,17 +71,16 @@ class NameCase < String
|
|
48
71
|
localstring.gsub!(
|
49
72
|
/ \b ( (?: [Xx]{1,3} | [Xx][Ll] | [Ll][Xx]{0,3} )?
|
50
73
|
(?: [Ii]{1,3} | [Ii][VvXx] | [Vv][Ii]{0,3} )? ) \b /x
|
51
|
-
) { |
|
74
|
+
) { |m| m.upcase }
|
52
75
|
|
53
76
|
localstring
|
54
77
|
end
|
78
|
+
end
|
55
79
|
|
56
|
-
|
57
|
-
|
58
|
-
self.gsub!(self, self.nc)
|
59
|
-
end
|
80
|
+
def NameCase(string, options = {})
|
81
|
+
NameCase.nc string, options
|
60
82
|
end
|
61
83
|
|
62
|
-
def NameCase
|
63
|
-
NameCase.
|
84
|
+
def NameCase!(string, options = {})
|
85
|
+
NameCase.nc! string, options
|
64
86
|
end
|
data/namecase.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: namecase 2.0.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "namecase"
|
6
|
+
s.version = "2.0.0"
|
7
|
+
|
8
|
+
s.require_paths = ["lib"]
|
9
|
+
s.authors = ["Aaron Patterson"]
|
10
|
+
s.date = "2015-03-01"
|
11
|
+
s.description = "NameCase is a Ruby implementation of `Lingua::EN::NameCase`, a library for\nconverting strings to be properly cased. This is good for converting\ndenormalized data to human friendly data."
|
12
|
+
s.email = ["aaronp@rubyforge.org"]
|
13
|
+
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.txt"]
|
14
|
+
s.files = [".gemtest", "Gemfile", "History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/namecase.rb", "test/test_namecase.rb"]
|
15
|
+
s.homepage = "http://namecase.rubyforge.org/"
|
16
|
+
s.licenses = ["GPL"]
|
17
|
+
s.rdoc_options = ["--main", "README.md"]
|
18
|
+
s.rubygems_version = "2.4.5"
|
19
|
+
s.summary = "NameCase is a Ruby implementation of `Lingua::EN::NameCase`, a library for converting strings to be properly cased"
|
20
|
+
s.test_files = ["test/test_namecase.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 4
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
|
27
|
+
s.add_development_dependency(%q<minitest>, ["~> 4.0"])
|
28
|
+
s.add_development_dependency(%q<hoe>, ["~> 3.13"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
31
|
+
s.add_dependency(%q<minitest>, ["~> 4.0"])
|
32
|
+
s.add_dependency(%q<hoe>, ["~> 3.13"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
36
|
+
s.add_dependency(%q<minitest>, ["~> 4.0"])
|
37
|
+
s.add_dependency(%q<hoe>, ["~> 3.13"])
|
38
|
+
end
|
39
|
+
end
|
data/test/test_namecase.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
4
3
|
require 'namecase'
|
5
|
-
require '
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class TestNameCase < Test
|
6
|
+
class TestNameCase < Minitest::Test
|
8
7
|
def setup
|
9
8
|
@proper_names = [
|
10
9
|
"Keith", "Leigh-Williams", "McCarthy",
|
@@ -31,25 +30,24 @@ class TestNameCase < Test::Unit::TestCase
|
|
31
30
|
|
32
31
|
def test_namecase
|
33
32
|
@proper_names.each do |name|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
assert_equal(name, NameCase(name.downcase))
|
34
|
+
n = name.dup
|
35
|
+
n.extend(NameCase)
|
36
|
+
assert_equal(name, n.nc)
|
37
37
|
assert_equal(name, NameCase(name))
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_namecase_modify
|
42
42
|
@proper_names.each do |name|
|
43
|
-
nc_name = NameCase
|
44
|
-
assert_equal(name, nc_name
|
43
|
+
nc_name = NameCase!(name.downcase)
|
44
|
+
assert_equal(name, nc_name)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_namecase_multibyte
|
49
|
-
$KCODE = 'u'
|
50
|
-
|
51
49
|
proper_cased = 'Iñtërnâtiônàlizætiøn'
|
52
|
-
nc_name = NameCase
|
53
|
-
assert_equal(proper_cased, nc_name
|
50
|
+
nc_name = NameCase(proper_cased.downcase)
|
51
|
+
assert_equal(proper_cased, nc_name)
|
54
52
|
end
|
55
53
|
end
|
metadata
CHANGED
@@ -1,73 +1,107 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: namecase
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Aaron Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
16
42
|
name: hoe
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.13'
|
17
48
|
type: :development
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
|
25
|
-
|
26
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.13'
|
55
|
+
description: |-
|
56
|
+
NameCase is a Ruby implementation of `Lingua::EN::NameCase`, a library for
|
57
|
+
converting strings to be properly cased. This is good for converting
|
58
|
+
denormalized data to human friendly data.
|
59
|
+
email:
|
27
60
|
- aaronp@rubyforge.org
|
28
61
|
executables: []
|
29
|
-
|
30
62
|
extensions: []
|
31
|
-
|
32
|
-
extra_rdoc_files:
|
63
|
+
extra_rdoc_files:
|
33
64
|
- History.txt
|
34
65
|
- LICENSE.txt
|
35
66
|
- Manifest.txt
|
36
|
-
- README.
|
37
|
-
files:
|
67
|
+
- README.md
|
68
|
+
files:
|
69
|
+
- ".gemtest"
|
70
|
+
- Gemfile
|
38
71
|
- History.txt
|
39
72
|
- LICENSE.txt
|
40
73
|
- Manifest.txt
|
41
|
-
- README.
|
74
|
+
- README.md
|
42
75
|
- Rakefile
|
43
76
|
- lib/namecase.rb
|
77
|
+
- namecase.gemspec
|
44
78
|
- test/test_namecase.rb
|
45
|
-
|
46
|
-
|
79
|
+
homepage: http://namecase.rubyforge.org/
|
80
|
+
licenses:
|
81
|
+
- GPL
|
82
|
+
metadata: {}
|
47
83
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
- --main
|
50
|
-
- README.
|
51
|
-
require_paths:
|
84
|
+
rdoc_options:
|
85
|
+
- "--main"
|
86
|
+
- README.md
|
87
|
+
require_paths:
|
52
88
|
- lib
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
-
requirements:
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
55
91
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
|
59
|
-
|
60
|
-
requirements:
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
61
96
|
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version:
|
64
|
-
version:
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
65
99
|
requirements: []
|
66
|
-
|
67
|
-
|
68
|
-
rubygems_version: 1.2.0
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
69
102
|
signing_key:
|
70
|
-
specification_version:
|
71
|
-
summary: NameCase is a Ruby implementation of Lingua::EN::NameCase
|
72
|
-
|
103
|
+
specification_version: 4
|
104
|
+
summary: NameCase is a Ruby implementation of `Lingua::EN::NameCase`, a library for
|
105
|
+
converting strings to be properly cased
|
106
|
+
test_files:
|
73
107
|
- test/test_namecase.rb
|
data/README.txt
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
= NameCase
|
2
|
-
|
3
|
-
http://namecase.rubyforge.org/
|
4
|
-
|
5
|
-
== DESCRIPTION
|
6
|
-
|
7
|
-
NameCase is a Ruby implementation of Lingua::EN::NameCase, a library for
|
8
|
-
converting strings to be properly cased. This is good for converting
|
9
|
-
denormalized data to human friendly data.
|
10
|
-
|
11
|
-
* Example Usage
|
12
|
-
|
13
|
-
NameCase("RON BURGUNDY") # => Ron Burgundy
|
14
|
-
NameCase("MCDONALDS") # => McDonalds
|
15
|
-
|
16
|
-
* Acknowledgements
|
17
|
-
|
18
|
-
This library is a port of the Perl library, and owes most of its functionality
|
19
|
-
to the Perl version by Mark Summerfield. Any bugs in the Ruby port are my
|
20
|
-
fault.
|
21
|
-
|
22
|
-
* Author
|
23
|
-
|
24
|
-
Original Version:
|
25
|
-
Copyright (c) Mark Summerfield 1998-2002.
|
26
|
-
<summer@perlpress.com>
|
27
|
-
All Rights Reserved
|
28
|
-
|
29
|
-
Ruby Version:
|
30
|
-
Copyright (c) Aaron Patterson 2006
|
31
|
-
|
32
|
-
* License
|
33
|
-
|
34
|
-
NameCase is distributed under the GPL license. Please see the LICENSE file.
|