nameable 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/examples/nameable_web_service.rb +22 -0
- data/examples/test.rb +45 -0
- data/lib/nameable.rb +34 -8
- data/nameable.gemspec +5 -3
- metadata +5 -3
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'date'
|
|
5
5
|
require 'spec/rake/spectask'
|
6
6
|
|
7
7
|
GEM = "nameable"
|
8
|
-
GEM_VERSION = "0.
|
8
|
+
GEM_VERSION = "0.5.0"
|
9
9
|
AUTHOR = "Chris Horn"
|
10
10
|
EMAIL = "chorn@chorn.com"
|
11
11
|
HOMEPAGE = "http://github.com/chorn/nameable"
|
@@ -22,10 +22,10 @@ spec = Gem::Specification.new do |s|
|
|
22
22
|
s.author = AUTHOR
|
23
23
|
s.email = EMAIL
|
24
24
|
s.homepage = HOMEPAGE
|
25
|
-
|
25
|
+
|
26
26
|
# Uncomment this to add a dependency
|
27
27
|
# s.add_dependency "foo"
|
28
|
-
|
28
|
+
|
29
29
|
s.require_path = 'lib'
|
30
30
|
s.autorequire = GEM
|
31
31
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "json"
|
5
|
+
require "sinatra"
|
6
|
+
require "nameable"
|
7
|
+
|
8
|
+
get '/*/*.*' do |raw_name, function, type|
|
9
|
+
begin
|
10
|
+
name = Nameable::Latin.new.parse(raw_name)
|
11
|
+
rescue Nameable::Latin::InvalidNameError => e
|
12
|
+
""
|
13
|
+
end
|
14
|
+
|
15
|
+
if type.to_sym == :json
|
16
|
+
content_type 'application/json'
|
17
|
+
name.to_hash.to_json
|
18
|
+
else
|
19
|
+
content_type 'text/plain'
|
20
|
+
name.send("to_#{function}") if function =~ /^(fullname|nameable|firstname|lastname|middlename)$/
|
21
|
+
end
|
22
|
+
end
|
data/examples/test.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "./lib/nameable"
|
5
|
+
|
6
|
+
DATA.each do |testcase|
|
7
|
+
n = Nameable::Latin.new.parse(testcase)
|
8
|
+
puts "``#{testcase.chomp}'' -> #{n.first} #{n.last} // #{n.to_fullname}"
|
9
|
+
end
|
10
|
+
|
11
|
+
__END__
|
12
|
+
HORN, CHRIS K
|
13
|
+
HORN, CHRIS K.
|
14
|
+
Mr. Chris Horn PhD
|
15
|
+
Chris Horn T.I.T.L.E.
|
16
|
+
Chris Horn II
|
17
|
+
Chris Horn II Esquire
|
18
|
+
Chris O'Horn
|
19
|
+
Chris McHorn
|
20
|
+
Chris Von Horn
|
21
|
+
Chris O' Horn
|
22
|
+
Chris K Horn
|
23
|
+
Chris K. Horn
|
24
|
+
Chris K Horn Sr
|
25
|
+
Chris Horn - Horn
|
26
|
+
Chris Ole Biscuit Barrel Horn
|
27
|
+
CHRIS HORN
|
28
|
+
CHRIS-HORN
|
29
|
+
CHRIS;HORN
|
30
|
+
Horn, Chris
|
31
|
+
Horn, Chris K
|
32
|
+
Horn, Chris K.
|
33
|
+
Horn, Chris K. DDS
|
34
|
+
Horn,,Chris
|
35
|
+
Horn,, Chris
|
36
|
+
Horn , , Chris
|
37
|
+
Horn ,, Chris
|
38
|
+
Chris Horn, Ph.D. DB CCNE
|
39
|
+
CHRIS MC HORN
|
40
|
+
CHRIS MAC HORN
|
41
|
+
CHRIS VAN HORN
|
42
|
+
CHRIS DA HORN
|
43
|
+
CHRIS DE HORN
|
44
|
+
CHRIS ST HORN
|
45
|
+
CHRIS ST. HORN
|
data/lib/nameable.rb
CHANGED
@@ -37,8 +37,10 @@ module Nameable
|
|
37
37
|
SUFFIX_PROFESSIONAL = /^(PE|CSA|CPA|CPL|CME|CEng|OFM|CSV|Douchebag)$/i
|
38
38
|
SUFFIX_ABBREVIATION = /^[A-Z\.]+[A-Z\.]+$/ # It should be at least 2 letters
|
39
39
|
|
40
|
-
LAST_NAME_PRE_DANGLERS = /^(vere|von|van|de|del|della|di|da|pietro|vanden|du|st|la|ter|ten)$/i
|
41
|
-
|
40
|
+
LAST_NAME_PRE_DANGLERS = /^(mc|vere|von|van|da|de|del|della|di|da|pietro|vanden|du|st|la|ter|ten)$/i
|
41
|
+
O_LAST_NAME_PRE_CONCATS = /^(o'|o`)$/i
|
42
|
+
# MC_LAST_NAME_PRE_CONCAT = /^(mc|da|de)$/i
|
43
|
+
# ST_LAST_NAME_PRE_CONCAT = /^(st)\.*$/i
|
42
44
|
end
|
43
45
|
|
44
46
|
attr_accessor :prefix, :first, :middle, :last, :suffix
|
@@ -85,7 +87,7 @@ module Nameable
|
|
85
87
|
if name.join != name.join.upcase and name[n].length > 1 and name[n] =~ Patterns::SUFFIX_ABBREVIATION
|
86
88
|
suff = name[n].upcase.gsub(/\./,'')
|
87
89
|
end
|
88
|
-
|
90
|
+
|
89
91
|
if suff
|
90
92
|
@suffix = @suffix ? "#{suff}, #{@suffix}" : suff
|
91
93
|
name.delete_at(n)
|
@@ -123,11 +125,15 @@ module Nameable
|
|
123
125
|
|
124
126
|
(name.size - 1).downto(0) do |n|
|
125
127
|
next unless name[n]
|
126
|
-
|
128
|
+
|
127
129
|
if name[n] =~ Patterns::LAST_NAME_PRE_DANGLERS
|
128
|
-
@last = "#{name[n]} #{@last}"
|
129
|
-
elsif name[n] =~ Patterns::
|
130
|
+
@last = "#{name[n].downcase.capitalize} #{@last}"
|
131
|
+
elsif name[n] =~ Patterns::O_LAST_NAME_PRE_CONCATS
|
130
132
|
@last = "O'#{@last}"
|
133
|
+
# elsif name[n] =~ Patterns::MC_LAST_NAME_PRE_CONCAT
|
134
|
+
# @last = "#{name[n].downcase.capitalize} #{@last}"
|
135
|
+
# elsif name[n] =~ Patterns::ST_LAST_NAME_PRE_CONCAT
|
136
|
+
# @last = "St. #{@last}"
|
131
137
|
elsif name[n] =~ /-+/ and n > 0 and name[n-1]
|
132
138
|
@last = "#{name[n-1]}-#{@last}"
|
133
139
|
name[n-1] = nil
|
@@ -177,10 +183,30 @@ module Nameable
|
|
177
183
|
to_s
|
178
184
|
end
|
179
185
|
|
186
|
+
def to_prefix
|
187
|
+
@prefix
|
188
|
+
end
|
189
|
+
|
190
|
+
def to_firstname
|
191
|
+
@first
|
192
|
+
end
|
193
|
+
|
194
|
+
def to_lastname
|
195
|
+
@last
|
196
|
+
end
|
197
|
+
|
198
|
+
def to_middlename
|
199
|
+
@middle
|
200
|
+
end
|
201
|
+
|
202
|
+
def to_suffix
|
203
|
+
@suffix
|
204
|
+
end
|
205
|
+
|
180
206
|
def to_nameable
|
181
207
|
[@first, @last].compact.join(' ')
|
182
208
|
end
|
183
|
-
|
209
|
+
|
184
210
|
def to_hash
|
185
211
|
return {
|
186
212
|
:prefix => @prefix,
|
@@ -190,5 +216,5 @@ module Nameable
|
|
190
216
|
:suffix => @suffix
|
191
217
|
}
|
192
218
|
end
|
193
|
-
end
|
219
|
+
end
|
194
220
|
end
|
data/nameable.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "nameable"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2012-
|
3
|
+
s.version = "0.5.0"
|
4
|
+
s.date = "2012-06-06"
|
5
5
|
s.summary = "Provides parsing and output of person names."
|
6
6
|
s.email = "chorn@chorn.com"
|
7
7
|
s.homepage = "http://github.com/chorn/nameable"
|
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
"script/destroy",
|
18
18
|
"script/generate",
|
19
19
|
"spec/nameable_spec.rb",
|
20
|
-
"spec/spec_helper.rb"
|
20
|
+
"spec/spec_helper.rb",
|
21
|
+
"examples/test.rb",
|
22
|
+
"examples/nameable_web_service.rb"
|
21
23
|
]
|
22
24
|
s.test_files = []
|
23
25
|
s.rdoc_options = []
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nameable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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: 2012-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A gem that provides parsing and output of person names.
|
15
15
|
email: chorn@chorn.com
|
@@ -27,6 +27,8 @@ files:
|
|
27
27
|
- script/generate
|
28
28
|
- spec/nameable_spec.rb
|
29
29
|
- spec/spec_helper.rb
|
30
|
+
- examples/test.rb
|
31
|
+
- examples/nameable_web_service.rb
|
30
32
|
homepage: http://github.com/chorn/nameable
|
31
33
|
licenses: []
|
32
34
|
post_install_message:
|
@@ -47,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
version: '0'
|
48
50
|
requirements: []
|
49
51
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
52
|
+
rubygems_version: 1.8.23
|
51
53
|
signing_key:
|
52
54
|
specification_version: 3
|
53
55
|
summary: Provides parsing and output of person names.
|