Skip to content

Commit 78961c9

Browse files
committed
Lots of new better nicer tests, and a few tweaks based on failed tests.
1 parent b3e3ffd commit 78961c9

26 files changed

+185451
-507
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
*.gem
3+
.idea

Gemfile

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
group :development do
4-
gem "bundler"
5-
gem "jeweler"
6-
end
7-
8-
group :test do
9-
gem "rspec"
10-
end
3+
gemspec

Gemfile.lock

+21-54
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,31 @@
1+
PATH
2+
remote: .
3+
specs:
4+
nameable (1.0.0)
5+
16
GEM
27
remote: https://rubygems.org/
38
specs:
4-
addressable (2.3.5)
5-
builder (3.2.2)
6-
descendants_tracker (0.0.3)
79
diff-lcs (1.2.5)
8-
faraday (0.9.0)
9-
multipart-post (>= 1.2, < 3)
10-
git (1.2.6)
11-
github_api (0.11.3)
12-
addressable (~> 2.3)
13-
descendants_tracker (~> 0.0.1)
14-
faraday (~> 0.8, < 0.10)
15-
hashie (>= 1.2)
16-
multi_json (>= 1.7.5, < 2.0)
17-
nokogiri (~> 1.6.0)
18-
oauth2
19-
hashie (2.0.5)
20-
highline (1.6.20)
21-
jeweler (2.0.1)
22-
builder
23-
bundler (>= 1.0)
24-
git (>= 1.2.5)
25-
github_api
26-
highline (>= 1.6.15)
27-
nokogiri (>= 1.5.10)
28-
rake
29-
rdoc
30-
json (1.8.1)
31-
jwt (0.1.11)
32-
multi_json (>= 1.5)
33-
mini_portile (0.5.2)
34-
multi_json (1.8.4)
35-
multi_xml (0.5.5)
36-
multipart-post (2.0.0)
37-
nokogiri (1.6.1)
38-
mini_portile (~> 0.5.0)
39-
oauth2 (0.9.3)
40-
faraday (>= 0.8, < 0.10)
41-
jwt (~> 0.1.8)
42-
multi_json (~> 1.3)
43-
multi_xml (~> 0.5)
44-
rack (~> 1.2)
45-
rack (1.5.2)
4610
rake (10.1.1)
47-
rdoc (4.1.1)
48-
json (~> 1.4)
49-
rspec (2.14.1)
50-
rspec-core (~> 2.14.0)
51-
rspec-expectations (~> 2.14.0)
52-
rspec-mocks (~> 2.14.0)
53-
rspec-core (2.14.7)
54-
rspec-expectations (2.14.5)
55-
diff-lcs (>= 1.1.3, < 2.0)
56-
rspec-mocks (2.14.6)
11+
rspec (3.0.0)
12+
rspec-core (~> 3.0.0)
13+
rspec-expectations (~> 3.0.0)
14+
rspec-mocks (~> 3.0.0)
15+
rspec-core (3.0.2)
16+
rspec-support (~> 3.0.0)
17+
rspec-expectations (3.0.2)
18+
diff-lcs (>= 1.2.0, < 2.0)
19+
rspec-support (~> 3.0.0)
20+
rspec-mocks (3.0.2)
21+
rspec-support (~> 3.0.0)
22+
rspec-support (3.0.2)
5723

5824
PLATFORMS
5925
ruby
6026

6127
DEPENDENCIES
62-
bundler
63-
jeweler
64-
rspec
28+
bundler (>= 1.6.2)
29+
nameable!
30+
rake
31+
rspec (~> 3.0.0)

History.txt

-11
This file was deleted.

LICENSE LICENSE.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Copyright (c) 2008 Chris Horn http://chorn.com/
22

3+
MIT License
4+
35
Permission is hereby granted, free of charge, to any person obtaining
46
a copy of this software and associated documentation files (the
57
"Software"), to deal in the Software without restriction, including

README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# nameable
2+
3+
A library that provides parsing and normalization of people's names.
4+
5+
```ruby
6+
require 'nameable'
7+
n = Nameable::Latin.new.parse('Mr. Chris K Horn Esquire')
8+
puts "#{n.prefix} #{n.first} #{n.middle} #{n.last} #{n.suffix}"
9+
#=> Mr. Chris K Horn Esq.
10+
puts n.to_fullname
11+
#=> Mr. Chris K. Horn, Esq.
12+
n = Nameable::Latin.new('CHRIS', 'HORN')
13+
puts n.to_nameable
14+
#=> Chris Horn
15+
n = Nameable::Latin.new(prefix:'Sir', last:'Horn')
16+
puts n
17+
#=> Sir Horn
18+
```
19+
20+
# Features
21+
22+
Convenience methods:
23+
```ruby
24+
puts Nameable('chris horn, iii')
25+
#=> "Chris Horn, III."
26+
puts Nameable.parse('chris horn, iii')
27+
#=> #<Nameable::Latin:0x007f8470e01b08 @first="Chris", @last="Horn", @middle=nil, @prefix=nil, @suffix="III.">
28+
```
29+
Using a database of first names from the U.S. Social Security Administration, Nameable will make a guess at the gender of a name.
30+
31+
```ruby
32+
Nameable::Latin.new('Chris').gender
33+
#=> :male
34+
Nameable::Latin.new('Janine').female?
35+
#=> true
36+
```
37+
Using a database of last names from the U.S. Census, Nameable will return the ethnicity breakdown as a Hash.
38+
```ruby
39+
Nameable::Latin.new('Chris', 'Horn').ethnicity
40+
#=> {:rank=>593, :count=>51380, :percent_white=>86.75, :percent_black=>8.31, :percent_asian_pacific_islander=>0.84, :percent_american_indian_alaska_native=>1.16, :percent_two_or_more_races=>1.46, :percent_hispanic=>1.48}
41+
```
42+
43+
# Other uses
44+
45+
I've included a little web service, which should be installed as "nameable_web_service" that requires sinatra. It's been handy when paired with OpenRefine, if I'm working with a file and I am not going to be parsing with Ruby. If you're reading this, that's probably not an issue for you, but I do think it's a nice way to show someone how to use OpenRefine in a more advanced way.
46+
47+
# Inspiration
48+
49+
By inspiration, I should really say "other projects from which I yanked their code, ideas, examples and data." At worst I'll make sure the other projects I looked at and borrowed from are credited here.
50+
51+
# References
52+
53+
* [Open Refine](http://openrefine.org/) formerly [Google Refine](https://code.google.com/p/google-refine/)
54+
* [Help with splitting names](http://www.onlineaspect.com/2009/08/17/splitting-names/)
55+
* [First Names from the U.S. SSA](http://www.ssa.gov/oact/babynames/limits.html)
56+
* [Last Names from the Census](http://www.census.gov/genealogy/www/data/2000surnames/index.html)
57+
* [Data Science Toolkit](https://github.com/petewarden/dstk)
58+
* [Addressable](https://github.com/sporkmonger/addressable)
59+
60+
# Issues
61+
62+
Thus far I've gone long stretches where this project did exactly what I needed it to, until it did not. I don't use it to validate or massage names with code connected to some kind of UI, I use it to clean up names I am parsing in volume. Hopefully I'm balancing speed and quality. Anything you don't like, change, you can have the commit bit easy-peasy.
63+
64+
The first time an instance of Nameable uses the gender method, the database of first names shipped with the gem will be parsed. The same is true for the last name data which is quite a bit larger. They aren't huge, and it only happens the first time, which is why I opted to leave the data in the gem, and not split it up into a different thing. If you hate that more than you hate gems that require extra steps to be useable let me know.
65+
66+
Oh, and github, pull request, workflow, yada yada.
67+
68+
-chorn

README.rdoc

-29
This file was deleted.

Rakefile

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,2 @@
1-
# encoding: utf-8
2-
3-
require 'rubygems'
4-
require 'bundler'
5-
begin
6-
Bundler.setup(:default, :development)
7-
rescue Bundler::BundlerError => e
8-
$stderr.puts e.message
9-
$stderr.puts "Run `bundle install` to install missing gems"
10-
exit e.status_code
11-
end
12-
require 'rake'
13-
14-
require 'jeweler'
15-
Jeweler::Tasks.new do |gem|
16-
gem.name = "nameable"
17-
gem.homepage = "https://github.com/chorn/nameable"
18-
gem.license = "MIT"
19-
gem.summary = %Q{Provides parsing and output of person names.}
20-
gem.description = %Q{A gem that provides parsing and output of person names.}
21-
gem.email = "[email protected]"
22-
gem.authors = ["Chris Horn"]
23-
gem.files = FileList['lib/**/*.rb', 'Gemfile*', '[A-Z]*', 'Rakefile', 'spec/*', 'examples/*'].to_a
24-
end
25-
Jeweler::RubygemsDotOrgTasks.new
26-
27-
require 'rspec/core'
28-
require 'rspec/core/rake_task'
29-
RSpec::Core::RakeTask.new(:spec) do |spec|
30-
spec.pattern = FileList['spec/**/*_spec.rb']
31-
end
32-
33-
RSpec::Core::RakeTask.new(:rcov) do |spec|
34-
spec.pattern = 'spec/**/*_spec.rb'
35-
spec.rcov = true
36-
end
37-
38-
task :default => :spec
1+
require "bundler/gem_tasks"
392

TODO

-3
This file was deleted.

VERSION

-1
This file was deleted.

examples/nameable_web_service.rb bin/nameable_web_service

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
# I use this with OpenRefine: http://openrefine.org/
4+
35
require "rubygems"
46
require "json"
57
require "sinatra"
@@ -8,7 +10,7 @@
810
get '/*/*.*' do |raw_name, function, type|
911
begin
1012
name = Nameable::Latin.new.parse(raw_name)
11-
rescue Nameable::Latin::InvalidNameError => e
13+
rescue Nameable::Latin::InvalidNameError
1214
""
1315
end
1416

0 commit comments

Comments
 (0)