monikers 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/README.md +44 -2
- data/lib/data/monikers_hash.rb +5 -4
- data/lib/data/monikers_list.csv +3 -0
- data/lib/monikers.rb +1 -1
- data/lib/monikers/version.rb +1 -1
- data/monikers.gemspec +1 -0
- data/spec/models/monikers_spec.rb +73 -0
- data/spec/spec_helper.rb +20 -0
- metadata +24 -3
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Monikers
|
2
2
|
|
3
|
-
|
3
|
+
Monikers is a _very_ simple Gem for listing and comparing first name 'monikers', or
|
4
|
+
nicknames. If a 3rd party, web based API is overkill for your needs, but simple
|
5
|
+
string or regex comparison is not sufficient, Monikers can fill the gap.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,10 +20,50 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
Monikers.list("Bob") # => ["robert", "rob", "bobby", "bert", "bob"]
|
24
|
+
Monikers.list("Polycarp") # => ["polycarp"]
|
25
|
+
Monikers.equivalents?("Sam", "Samuel") # => true
|
26
|
+
Monikers.equivalents?("Mike", "Matt") # => false
|
27
|
+
|
28
|
+
## Implementation
|
29
|
+
|
30
|
+
Monikers uses a static hash to lookup nicknames. The data structure is
|
31
|
+
pre-built, stored in a flat file (`lib/data/monikers_hash.rb`) and `eval`'d
|
32
|
+
when needed.
|
33
|
+
|
34
|
+
The nickname hash is compiled from a static list of names in CSV format
|
35
|
+
(`lib/data/monikers_list.csv`). This CSV is not accessed unless
|
36
|
+
`Monikers::Generator.generate_cache` method is called. **This should not be done
|
37
|
+
in normal use of the Gem**, such as during the execution of a routine using
|
38
|
+
Monikers. Instead, it should only be done ahead of time to add or modify
|
39
|
+
names in the hash cache. See the "Add or Modify" names section under "Contributing"
|
40
|
+
below.
|
22
41
|
|
23
42
|
## Contributing
|
24
43
|
|
44
|
+
### Add or Modify Names
|
45
|
+
To add or modify names to the Monikers cache, make the changes to the static
|
46
|
+
CSV, then run the generator on your local development machine to update the
|
47
|
+
static data structure.
|
48
|
+
|
49
|
+
$ cd path/to/monikers
|
50
|
+
$ cd lib/monikers/generator/
|
51
|
+
$ irb
|
52
|
+
> require './generator.rb'
|
53
|
+
> Monikers::Generator.generate_cache
|
54
|
+
|
55
|
+
`lib/data/monikders_hash.rb` should have been modified to include your changes.
|
56
|
+
It is requested that if you submit a patch including new names or nicknames, that you
|
57
|
+
write a test or two for at least some of the new names created.
|
58
|
+
|
59
|
+
Submit all changes in one commit (example: 54e49341efce2a6bcfef84c41598cf5dce48714e)
|
60
|
+
via pull request.
|
61
|
+
|
62
|
+
### Modifying Gem functionality or tests
|
63
|
+
The Monikers Gem is simple by design. Pull requests for complex changes or
|
64
|
+
functionality may not be accepted. If you think you have a helpful addition or
|
65
|
+
correction to the Gem or its tests, use a standard fork & branch workflow:
|
66
|
+
|
25
67
|
1. Fork it
|
26
68
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
69
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/lib/data/monikers_hash.rb
CHANGED
@@ -241,10 +241,10 @@
|
|
241
241
|
"belinda"=>["belle", "linda"],
|
242
242
|
"linda"=>
|
243
243
|
["belinda", "lindy", "lynn", "melinda", "philinda", "rosalinda", "rosalyn"],
|
244
|
-
"benedict"=>["ben", "bennie"],
|
245
|
-
"ben"=>["benedict", "benjamin", "bennie", "jamie"],
|
244
|
+
"benedict"=>["ben", "bennie", "benny"],
|
245
|
+
"ben"=>["benedict", "benjamin", "bennie", "jamie", "benny"],
|
246
246
|
"bennie"=>["benedict", "benjamin", "ben"],
|
247
|
-
"benjamin"=>["ben", "benjy", "bennie", "jamie"],
|
247
|
+
"benjamin"=>["ben", "benjy", "bennie", "jamie", "benny"],
|
248
248
|
"benjy"=>["benjamin"],
|
249
249
|
"jamie"=>["benjamin", "james", "ben"],
|
250
250
|
"bernard"=>["barney", "berney", "bernie"],
|
@@ -1360,4 +1360,5 @@
|
|
1360
1360
|
"cheryl"=>["sheryl"],
|
1361
1361
|
"sheryl"=>["cheryl", "sher"],
|
1362
1362
|
"cher"=>["sher"],
|
1363
|
-
"nik"=>["nick"]
|
1363
|
+
"nik"=>["nick"],
|
1364
|
+
"benny"=>["benedict", "benjamin", "ben"]}
|
data/lib/data/monikers_list.csv
CHANGED
data/lib/monikers.rb
CHANGED
data/lib/monikers/version.rb
CHANGED
data/monikers.gemspec
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Monikers do
|
4
|
+
|
5
|
+
it { should respond_to(:list).with(1).argument }
|
6
|
+
it { should respond_to(:equivalents?).with(2).arguments }
|
7
|
+
|
8
|
+
context "when calling Monikers twice" do
|
9
|
+
let(:monikers_list_one) { Monikers.list("Ben") }
|
10
|
+
let(:monikers_list_two) { Monikers.list("Ben") }
|
11
|
+
|
12
|
+
it "should should not add dupes to the dataset" do
|
13
|
+
monikers_list_one.size.should eq(monikers_list_two.size)
|
14
|
+
monikers_list_one.sort.should eq(monikers_list_two.sort)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when testing list method" do
|
19
|
+
context "when given Ben" do
|
20
|
+
let(:monikers_list) { Monikers.list("Ben") }
|
21
|
+
let(:correct_results) { ["benjamin", "jamie", "benedict", "bennie", "benny", "ben"] }
|
22
|
+
|
23
|
+
it "should return the correct monikers list" do
|
24
|
+
monikers_list.sort.should eq(correct_results.sort)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when given Polycarp" do
|
29
|
+
let(:monikers_list) { Monikers.list("Polycarp") }
|
30
|
+
let(:correct_results) { ["polycarp"] }
|
31
|
+
|
32
|
+
it "should return the correct monikers list" do
|
33
|
+
monikers_list.sort.should eq(correct_results.sort)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when given John vs. john" do
|
38
|
+
let(:lowcase_list) { Monikers.list("john") }
|
39
|
+
let(:upcase_list) { Monikers.list("John") }
|
40
|
+
|
41
|
+
it "should return the same list" do
|
42
|
+
lowcase_list.sort.should eq(upcase_list.sort)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when testing equivalents method" do
|
48
|
+
it "should match Bob and Robert" do
|
49
|
+
Monikers.equivalents?("Bob", "Robert").should eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not match Mike and Matt" do
|
53
|
+
Monikers.equivalents?("Mike", "Matt").should eq(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should match Polycarp and Polycarp" do
|
57
|
+
Monikers.equivalents?("Polycarp", "Polycarp").should eq(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should match joE and Joe" do
|
61
|
+
Monikers.equivalents?("joE", "Joe").should eq(true)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not match Jim and jOn" do
|
65
|
+
Monikers.equivalents?("Jim", "jOn").should eq(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should match Ben and Benny" do
|
69
|
+
Monikers.equivalents?("Ben", "Benny").should eq(true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
Dir[File.expand_path("../../spec/support/**/*.rb", __FILE__)].each {|f| require f}
|
7
|
+
|
8
|
+
require 'pry-debugger'
|
9
|
+
require 'monikers'
|
10
|
+
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monikers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.10'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry-debugger
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Cached List of First Name Monikers (nicknames) in easy-access Ruby Gem
|
31
47
|
email:
|
32
48
|
- bdifrancesco@ascensionpress.com
|
@@ -35,6 +51,7 @@ extensions: []
|
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
37
53
|
- .gitignore
|
54
|
+
- .rspec
|
38
55
|
- Gemfile
|
39
56
|
- LICENSE.txt
|
40
57
|
- README.md
|
@@ -45,6 +62,8 @@ files:
|
|
45
62
|
- lib/monikers/generator/generator.rb
|
46
63
|
- lib/monikers/version.rb
|
47
64
|
- monikers.gemspec
|
65
|
+
- spec/models/monikers_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
48
67
|
homepage: https://github.com/apbendi/monikers
|
49
68
|
licenses: []
|
50
69
|
post_install_message:
|
@@ -70,4 +89,6 @@ signing_key:
|
|
70
89
|
specification_version: 3
|
71
90
|
summary: Gem contains a precached data structure of first name monikers & convenience
|
72
91
|
methods for access & comparison
|
73
|
-
test_files:
|
92
|
+
test_files:
|
93
|
+
- spec/models/monikers_spec.rb
|
94
|
+
- spec/spec_helper.rb
|