nameable_record 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -21
- data/.rspec +4 -0
- data/.rvmrc +2 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +134 -0
- data/Guardfile +7 -0
- data/README.rdoc +0 -25
- data/Rakefile +1 -45
- data/lib/nameable_record/active_record_extensions.rb +16 -24
- data/lib/nameable_record/data/given-names.txt +5678 -0
- data/lib/nameable_record/data/surnames.txt +9527 -0
- data/lib/nameable_record/name.rb +56 -32
- data/lib/nameable_record/name_recognition.rb +119 -0
- data/lib/nameable_record/name_recognizer.rb +10 -0
- data/lib/nameable_record/railtie.rb +14 -0
- data/lib/nameable_record/version.rb +4 -0
- data/lib/nameable_record.rb +8 -6
- data/nameable_record.gemspec +23 -48
- data/script/environment.rb +17 -0
- data/spec/database.yml +4 -0
- data/spec/lib/nameable_record/active_record_extensions_spec.rb +43 -0
- data/spec/lib/nameable_record/name_recognition_sharedspec.rb +182 -0
- data/spec/lib/nameable_record/name_recognition_spec.rb +17 -0
- data/spec/lib/nameable_record/name_recognizer_spec.rb +17 -0
- data/spec/lib/nameable_record/name_spec.rb +239 -0
- data/spec/lib/nameable_record_spec.rb +8 -0
- data/spec/rails_spec_helper.rb +3 -0
- data/spec/spec_helper.rb +26 -6
- metadata +76 -27
- data/LICENSE +0 -20
- data/VERSION +0 -1
- data/spec/nameable_record_spec.rb +0 -7
- data/spec/spec.opts +0 -1
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NameableRecord::Name do
|
4
|
+
|
5
|
+
subject { name }
|
6
|
+
|
7
|
+
let :name do
|
8
|
+
described_class.new *name_parts
|
9
|
+
end
|
10
|
+
|
11
|
+
let :another_name do
|
12
|
+
described_class.new *name_parts
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be frozen after initialization' do
|
16
|
+
subject.should be_frozen
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should know when it is equal to another Name' do
|
20
|
+
subject.eql?( another_name ).should be_true
|
21
|
+
subject.==( another_name ).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'PREDEFINED_PATTERNS' do
|
25
|
+
|
26
|
+
subject { described_class::PREDEFINED_PATTERNS }
|
27
|
+
|
28
|
+
it { should == {
|
29
|
+
:full => "%l, %f %s",
|
30
|
+
:full_with_middle => "%l, %f %m %s",
|
31
|
+
:full_with_prefix => "%l, %p %f %s",
|
32
|
+
:full_sentence => "%p %f %l %s",
|
33
|
+
:full_sentence_with_middle => "%p %f %m %l %s"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'PATTERN_MAP' do
|
40
|
+
|
41
|
+
subject { described_class::PATTERN_MAP }
|
42
|
+
|
43
|
+
it { should == {
|
44
|
+
/%l/ => :last,
|
45
|
+
/%f/ => :first,
|
46
|
+
/%m/ => :middle,
|
47
|
+
/%p/ => :prefix,
|
48
|
+
/%s/ => :suffix
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'PREFIX_BASE' do
|
55
|
+
|
56
|
+
subject { described_class::PREFIX_BASE.sort }
|
57
|
+
|
58
|
+
it { should == %w(Mr Mrs Miss Dr General).sort }
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'SUFFIX_BASE' do
|
63
|
+
|
64
|
+
subject { described_class::SUFFIX_BASE.sort }
|
65
|
+
|
66
|
+
it { should == %w(Jr III IV V Esq).sort }
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'PREFIXES' do
|
71
|
+
|
72
|
+
subject { described_class::PREFIXES }
|
73
|
+
|
74
|
+
it { should == ["DR", "DR.", "Dr", "Dr.", "GENERAL", "GENERAL.", "General", "General.", "MISS", "MISS.", "MR", "MR.", "MRS", "MRS.", "Miss", "Miss.", "Mr", "Mr.", "Mrs", "Mrs.", "dr", "dr.", "general", "general.", "miss", "miss.", "mr", "mr.", "mrs", "mrs."] }
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'SUFFIXES' do
|
79
|
+
|
80
|
+
subject { described_class::SUFFIXES }
|
81
|
+
|
82
|
+
it { should == ["ESQ", "ESQ.", "Esq", "Esq.", "III", "III", "III.", "III.", "IV", "IV", "IV.", "IV.", "JR", "JR.", "Jr", "Jr.", "V", "V", "V.", "V.", "esq", "esq.", "iii", "iii.", "iv", "iv.", "jr", "jr.", "v", "v."] }
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context '#to_s' do
|
87
|
+
|
88
|
+
subject { name.to_s }
|
89
|
+
|
90
|
+
it { should == 'Smith, John' }
|
91
|
+
|
92
|
+
context 'when given a default pattern' do
|
93
|
+
|
94
|
+
context ':full' do
|
95
|
+
|
96
|
+
subject { name.to_s :full }
|
97
|
+
|
98
|
+
it { should == 'Smith, John III' }
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
context ':full' do
|
103
|
+
|
104
|
+
subject { name.to_s :full_with_middle }
|
105
|
+
|
106
|
+
it { should == 'Smith, John Jacob III' }
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
context ':full' do
|
111
|
+
|
112
|
+
subject { name.to_s :full_with_prefix }
|
113
|
+
|
114
|
+
it { should == 'Smith, Mr. John III' }
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
context ':full' do
|
119
|
+
|
120
|
+
subject { name.to_s :full_sentence }
|
121
|
+
|
122
|
+
it { should == 'Mr. John Smith III' }
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
context ':full' do
|
127
|
+
|
128
|
+
subject { name.to_s :full_sentence_with_middle }
|
129
|
+
|
130
|
+
it { should == 'Mr. John Jacob Smith III' }
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when given a pattern' do
|
137
|
+
|
138
|
+
context "'%f %l'" do
|
139
|
+
|
140
|
+
subject { name.to_s '%f %l' }
|
141
|
+
|
142
|
+
it { should == 'John Smith' }
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context "'%p %f %l'" do
|
147
|
+
|
148
|
+
subject { name.to_s '%p %f %l' }
|
149
|
+
|
150
|
+
it { should == 'Mr. John Smith' }
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
context "'%p %f %l %s'" do
|
155
|
+
|
156
|
+
subject { name.to_s '%p %f %l %s' }
|
157
|
+
|
158
|
+
it { should == 'Mr. John Smith III' }
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
context "'%p %f %m %l %s'" do
|
163
|
+
|
164
|
+
subject { name.to_s '%p %f %m %l %s' }
|
165
|
+
|
166
|
+
it { should == 'Mr. John Jacob Smith III' }
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
# context 'parsing' do
|
175
|
+
|
176
|
+
# context 'a string name' do
|
177
|
+
|
178
|
+
# context 'John Smith' do
|
179
|
+
|
180
|
+
# subject { described_class.parse( 'John Smith' ) }
|
181
|
+
|
182
|
+
# it { should == described_class.new( 'Smith', 'John' ) }
|
183
|
+
|
184
|
+
# end
|
185
|
+
|
186
|
+
# context 'John Jacob Smith' do
|
187
|
+
|
188
|
+
# subject { described_class.parse( 'John Jacob Smith' ) }
|
189
|
+
|
190
|
+
# it { should == described_class.new( 'Smith', 'John', nil, 'Jacob' ) }
|
191
|
+
|
192
|
+
# end
|
193
|
+
|
194
|
+
# context 'Mr. John Smith' do
|
195
|
+
|
196
|
+
# subject { described_class.parse( 'Mr. John Smith' ) }
|
197
|
+
|
198
|
+
# it { should == described_class.new( 'Smith', 'John', 'Mr.' ) }
|
199
|
+
|
200
|
+
# end
|
201
|
+
|
202
|
+
# context 'Mr. John Jacob Smith' do
|
203
|
+
|
204
|
+
# subject { described_class.parse( 'Mr. John Jacob Smith' ) }
|
205
|
+
|
206
|
+
# it { should == described_class.new( 'Smith', 'John', 'Mr.', 'Jacob' ) }
|
207
|
+
|
208
|
+
# end
|
209
|
+
|
210
|
+
# context 'John Jacob Smith Jr.' do
|
211
|
+
|
212
|
+
# subject { described_class.parse( 'John Jacob Smith Jr.' ) }
|
213
|
+
|
214
|
+
# it { should == described_class.new( 'Smith', 'John', nil, 'Jacob', 'Jr' ) }
|
215
|
+
|
216
|
+
# end
|
217
|
+
|
218
|
+
# context 'Mr. John Smith Jr' do
|
219
|
+
|
220
|
+
# subject { described_class.parse( 'Mr. John Smith Jr' ) }
|
221
|
+
|
222
|
+
# it { should == described_class.new( 'Smith', 'John', 'Mr.', nil, 'Jr' ) }
|
223
|
+
|
224
|
+
# end
|
225
|
+
|
226
|
+
# context 'Mr John Jacob Smith III' do
|
227
|
+
|
228
|
+
# subject { described_class.parse( 'Mr John Jacob Smith III' ) }
|
229
|
+
|
230
|
+
# it { should == described_class.new( 'Smith', 'John', 'Mr.', 'Jacob', 'III' ) }
|
231
|
+
|
232
|
+
# end
|
233
|
+
|
234
|
+
# end
|
235
|
+
|
236
|
+
# end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require 'rails'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
3
6
|
require 'nameable_record'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
RSpec.configure do |config|
|
9
|
+
|
10
|
+
config.mock_with :rspec
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def name_parts
|
15
|
+
%w(Smith John Mr. Jacob III)
|
9
16
|
end
|
17
|
+
|
18
|
+
class Hash
|
19
|
+
# for excluding keys
|
20
|
+
def except(*exclusions)
|
21
|
+
self.reject { |key, value| exclusions.include? key.to_sym }
|
22
|
+
end
|
23
|
+
|
24
|
+
# for overriding keys
|
25
|
+
def with(overrides = {})
|
26
|
+
self.merge overrides
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -2,68 +2,110 @@
|
|
2
2
|
name: nameable_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
hash: 23
|
5
|
-
prerelease:
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- Jason Harrelson
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-11-08 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: gem-dandy
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 3
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
- 9
|
34
|
-
version: 1.2.9
|
31
|
+
- 0
|
32
|
+
version: "0"
|
35
33
|
type: :development
|
36
34
|
version_requirements: *id001
|
37
|
-
|
38
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rails
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Abstracts the ActiveRecord composed_of pattern for names. Also provides other convenience utilieis for working with human names.
|
64
|
+
email:
|
65
|
+
- jason@lookforwardenterprises.com
|
39
66
|
executables: []
|
40
67
|
|
41
68
|
extensions: []
|
42
69
|
|
43
|
-
extra_rdoc_files:
|
44
|
-
|
45
|
-
- README.rdoc
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
46
72
|
files:
|
47
73
|
- .document
|
48
74
|
- .gitignore
|
49
|
-
-
|
75
|
+
- .rspec
|
76
|
+
- .rvmrc
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- Guardfile
|
50
80
|
- README.rdoc
|
51
81
|
- Rakefile
|
52
|
-
- VERSION
|
53
82
|
- lib/nameable_record.rb
|
54
83
|
- lib/nameable_record/active_record_extensions.rb
|
84
|
+
- lib/nameable_record/data/given-names.txt
|
85
|
+
- lib/nameable_record/data/surnames.txt
|
55
86
|
- lib/nameable_record/name.rb
|
87
|
+
- lib/nameable_record/name_recognition.rb
|
88
|
+
- lib/nameable_record/name_recognizer.rb
|
89
|
+
- lib/nameable_record/railtie.rb
|
90
|
+
- lib/nameable_record/version.rb
|
56
91
|
- nameable_record.gemspec
|
57
|
-
-
|
58
|
-
- spec/
|
92
|
+
- script/environment.rb
|
93
|
+
- spec/database.yml
|
94
|
+
- spec/lib/nameable_record/active_record_extensions_spec.rb
|
95
|
+
- spec/lib/nameable_record/name_recognition_sharedspec.rb
|
96
|
+
- spec/lib/nameable_record/name_recognition_spec.rb
|
97
|
+
- spec/lib/nameable_record/name_recognizer_spec.rb
|
98
|
+
- spec/lib/nameable_record/name_spec.rb
|
99
|
+
- spec/lib/nameable_record_spec.rb
|
100
|
+
- spec/rails_spec_helper.rb
|
59
101
|
- spec/spec_helper.rb
|
60
102
|
has_rdoc: true
|
61
|
-
homepage:
|
103
|
+
homepage: https://github.com/midas/nameable_record
|
62
104
|
licenses: []
|
63
105
|
|
64
106
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
|
107
|
+
rdoc_options: []
|
108
|
+
|
67
109
|
require_paths:
|
68
110
|
- lib
|
69
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,11 +128,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
128
|
version: "0"
|
87
129
|
requirements: []
|
88
130
|
|
89
|
-
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
131
|
+
rubyforge_project: nameable_record
|
132
|
+
rubygems_version: 1.6.0
|
91
133
|
signing_key:
|
92
134
|
specification_version: 3
|
93
|
-
summary:
|
135
|
+
summary: Abstracts the ActiveRecord composed_of pattern for names.
|
94
136
|
test_files:
|
95
|
-
- spec/
|
137
|
+
- spec/database.yml
|
138
|
+
- spec/lib/nameable_record/active_record_extensions_spec.rb
|
139
|
+
- spec/lib/nameable_record/name_recognition_sharedspec.rb
|
140
|
+
- spec/lib/nameable_record/name_recognition_spec.rb
|
141
|
+
- spec/lib/nameable_record/name_recognizer_spec.rb
|
142
|
+
- spec/lib/nameable_record/name_spec.rb
|
143
|
+
- spec/lib/nameable_record_spec.rb
|
144
|
+
- spec/rails_spec_helper.rb
|
96
145
|
- spec/spec_helper.rb
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 Jason Harrelson (midas)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|