Skip to content

Commit 4dc46df

Browse files
committed
Refactor tests and add better coverage
Update the Code Climate test reporter, which requires running SimpleCov locally and posting the results. I've also added a simple .rubocop.yml, added more rubies to the Travis CI config, and cleaned up a bunch of cruft. The README now has to-dos, which is pretty much a list of things I don't like about this code.
1 parent 08f4dba commit 4dc46df

23 files changed

+266
-451
lines changed

.rubocop.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
AllCops:
3+
TargetRubyVersion: 2.2
4+
5+
Style/Documentation:
6+
Enabled: false
7+
8+
Style/MethodName:
9+
Exclude:
10+
- lib/nameable/extensions.rb
11+
12+
Metrics/LineLength:
13+
Max: 132
14+
15+
Metrics/BlockLength:
16+
Exclude:
17+
- spec/*/**

.travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ language: ruby
22
cache: bundler
33
script: bundle exec rspec
44
rvm:
5-
- 2.4.1
6-
- 2.3.4
5+
- 1.9.3-p551
6+
- 2.0.0-p648
7+
- 2.1.10
78
- 2.2.7
9+
- 2.3.0
10+
- 2.3.4
11+
- 2.4.0
12+
- 2.4.1
813
dd:
914
secure: fzItORKaVrevTjQQu85FYgqgSVkRGG8PtOfNTCYY0meyP1+hF/lH6i5ZAb35VAuwi9InqaYnPx09dREBlfEqkzY/Ypxglq+EosAfqOgiKFu44JlM4vhxSdwn2mywCJpYZ0IbH5OnkF6rUULL/AoRQPlIV77eRqhB9LGfLNlYMfU=

Gemfile

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

3-
gemspec
3+
gemspec

Gemfile.lock

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
PATH
22
remote: .
33
specs:
4-
nameable (1.1.3)
4+
nameable (1.1.4)
55

66
GEM
77
remote: https://rubygems.org/
88
specs:
9-
codeclimate-test-reporter (0.6.0)
10-
simplecov (>= 0.7.1, < 1.0.0)
9+
codeclimate-test-reporter (1.0.8)
10+
simplecov (<= 0.13)
1111
diff-lcs (1.3)
1212
docile (1.1.5)
1313
json (2.1.0)
1414
json (2.1.0-java)
15-
rake (10.5.0)
15+
rake (12.0.0)
1616
rspec (3.6.0)
1717
rspec-core (~> 3.6.0)
1818
rspec-expectations (~> 3.6.0)
@@ -26,7 +26,7 @@ GEM
2626
diff-lcs (>= 1.2.0, < 2.0)
2727
rspec-support (~> 3.6.0)
2828
rspec-support (3.6.0)
29-
simplecov (0.14.1)
29+
simplecov (0.13.0)
3030
docile (~> 1.1.0)
3131
json (>= 1.8, < 3)
3232
simplecov-html (~> 0.10.0)
@@ -37,11 +37,12 @@ PLATFORMS
3737
ruby
3838

3939
DEPENDENCIES
40-
bundler (~> 1.6)
41-
codeclimate-test-reporter (~> 0.4)
40+
bundler
41+
codeclimate-test-reporter
4242
nameable!
43-
rake (~> 10.4)
44-
rspec (~> 3.3)
43+
rake
44+
rspec (~> 3.6)
45+
simplecov
4546

4647
BUNDLED WITH
4748
1.14.6

Guardfile

-57
This file was deleted.

README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ puts n
2323
# Features
2424

2525
Convenience methods:
26+
2627
```ruby
2728
puts Nameable('chris horn, iii')
2829
#=> "Chris Horn, III."
2930
puts Nameable.parse('chris horn, iii')
3031
#=> #<Nameable::Latin:0x007f8470e01b08 @first="Chris", @last="Horn", @middle=nil, @prefix=nil, @suffix="III.">
3132
```
33+
3234
Using a database of first names from the U.S. Social Security Administration, Nameable will pick the most likely gender for a name.
3335

3436
```ruby
@@ -37,7 +39,9 @@ Nameable::Latin.new('Chris').gender
3739
Nameable::Latin.new('Janine').female?
3840
#=> true
3941
```
42+
4043
Using a database of last names from the U.S. Census, Nameable will return the ethnicity breakdown as a Hash.
44+
4145
```ruby
4246
Nameable::Latin.new('Chris', 'Horn').ethnicity
4347
#=> {: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}
@@ -56,8 +60,8 @@ By inspiration, I should really say "other projects from which I yanked their co
5660
As of version `1.1.1`., the nameable gem is cryptographically signed. To be sure the gem you install hasn’t been tampered with, add my public key as a trusted certificate, and verify that nameable and any dependencies it has are also signed:
5761

5862
```
59-
gem cert --add <(curl -Ls https://raw.github.com/chorn/nameable/master/certs/chorn.pem)
60-
gem install nameable -P HighSecurity
63+
$ gem cert --add <(curl -Ls https://raw.github.com/chorn/nameable/master/certs/chorn.pem)
64+
$ gem install nameable -P HighSecurity
6165
```
6266

6367
# References
@@ -69,14 +73,12 @@ gem install nameable -P HighSecurity
6973
* [Data Science Toolkit](https://github.com/petewarden/dstk)
7074
* [Addressable](https://github.com/sporkmonger/addressable)
7175

72-
# Issues
73-
74-
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.
75-
76-
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.
77-
78-
I don't like that the Ethnicity data is just a Hash.
76+
# To-do
7977

80-
Oh, and github, pull request, workflow, yada yada.
78+
1. Extract all of the US Census / Ethnicity / Asset stuff out of `Latin`. Yuck, that's ugly why did I ever do that?
79+
2. Rename `Latin` to be `US` or `English` because it's looks like I really only support English, and probably US English.
80+
3. Use named captures for all the regexs.
81+
4. Refactor the Ethnicity stuff into a class.
82+
5. Refactor parsing into a class.
8183

8284
-chorn

Rakefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ require 'digest/sha2'
33

44
task default: %w[build]
55

6-
desc "Update checksums for gems in ./pkg"
6+
desc 'Update checksums for gems in ./pkg'
77
task :checksums do
88
Dir.glob('pkg/*.gem').each do |gem|
99
checksum = Digest::SHA512.new.hexdigest(File.read(gem))
10-
File.open("#{gem.gsub(/pkg/, 'checksums')}.sha512", 'w' ) {|f| f.write(checksum) }
10+
File.open("#{gem.gsub(/pkg/, 'checksums')}.sha512", 'w') { |f| f.write(checksum) }
1111
end
1212
end
13-

bin/nameable_web_service

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
# I use this with OpenRefine: http://openrefine.org/
44

5-
require "rubygems"
6-
require "json"
7-
require "sinatra"
8-
require "nameable"
5+
require 'rubygems'
6+
require 'json'
7+
require 'sinatra'
8+
require 'nameable'
99

1010
get '/*/*.*' do |raw_name, function, type|
1111
begin
1212
name = Nameable(raw_name)
1313
rescue Nameable::Latin::InvalidNameError
14-
""
14+
''
1515
end
1616

1717
if type.to_sym == :json

checksums/nameable-1.1.1.gem.sha512

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3da59e4a80b73488ec9745fcb9ca31b08db3e603df7b1ac0c572c4740f29b703563e47b3fff879a9e1cd5f103fcbf2883c8cfa146193924e0d351c7fe719ce38
1+
20c36413799bce5ac2fff4d2655449f3c53eaf9e88225fa4c61e88d5c5ee275224343294115e52a6be22f0dcd3328a9346f81836739371299e527b7e9307730b

checksums/nameable-1.1.3.gem.sha512

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b5b26ab87ee234cbfb4c75e83f35bf765ab2afef12f72742be74725a652231ec103e85a1811821acc59e221bcf5c7b0910b0466b2f4cdee506d5b9befe27dcf0

checksums/nameable-1.1.4.gem.sha512

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
071de8a4206e62e689131fd00f35a1d8d98d535ca574449baf92e3ffe207e6ed6f5a843c5cd8f040b148b8a2cfa918251621bd97482153084a7cd46d81961e9f

lib/nameable.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require "nameable/version"
2-
require "nameable/assets"
3-
require "nameable/error"
4-
require "nameable/latin"
5-
require "nameable/extensions"
1+
require 'nameable/version'
2+
require 'nameable/error'
3+
require 'nameable/assets'
4+
require 'nameable/latin'
5+
require 'nameable/extensions'
66

77
module Nameable
88
def self.parse(name)

lib/nameable/assets.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module Nameable::Assets
2-
GENDER_TABLE = File.expand_path(File.join('..', '..', '..', 'data', 'yob2016.txt'), __FILE__)
3-
ETHNICITY_TABLE = File.expand_path(File.join('..', '..', '..', 'data', 'app_c.csv'), __FILE__)
1+
module Nameable
2+
module Assets
3+
GENDER_TABLE = File.expand_path(File.join('..', '..', '..', 'data', 'yob2016.txt'), __FILE__)
4+
ETHNICITY_TABLE = File.expand_path(File.join('..', '..', '..', 'data', 'app_c.csv'), __FILE__)
5+
end
46
end

lib/nameable/error.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module Nameable
2-
# Raised if something other than a valid Name is supplied
32
class InvalidNameError < StandardError
43
end
54
end

0 commit comments

Comments
 (0)