nameable 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +5 -0
  2. data/lib/nameable.rb +22 -16
  3. data/nameable.gemspec +2 -2
  4. metadata +4 -4
@@ -13,12 +13,17 @@ require "nameable"
13
13
  n = Nameable::Latin.new.parse("Mr. Chris K Horn Esquire")
14
14
 
15
15
  puts n.prefix
16
+
16
17
  puts n.first
18
+
17
19
  puts n.middle
20
+
18
21
  puts n.last
22
+
19
23
  puts n.suffix
20
24
 
21
25
  puts n.to_fullname
22
26
 
23
27
 
28
+
24
29
  -chorn
@@ -15,27 +15,27 @@ module Nameable
15
15
  # Regex's to match the detritus that people add to their names
16
16
  module Patterns
17
17
  PREFIX = {
18
- "Mr." => /^\(*(mr\.*|mister)\)*$/i,
19
- "Mrs." => /^\(*(mrs\.*|misses)\)*$/i,
20
- "Ms." => /^\(*(ms\.*|miss)\)*$/i,
21
- "Dr." => /^\(*(dr\.*|doctor)\)*$/i,
22
- "Rev." => /^\(*(rev\.*|reverand)\)*$/i,
23
- "Fr." => /^\(*(fr\.*|friar)\)*$/i,
18
+ "Mr." => /^\(*(mr\.*|mister)\)*$/i,
19
+ "Mrs." => /^\(*(mrs\.*|misses)\)*$/i,
20
+ "Ms." => /^\(*(ms\.*|miss)\)*$/i,
21
+ "Dr." => /^\(*(dr\.*|doctor)\)*$/i,
22
+ "Rev." => /^\(*(rev\.*|reverand)\)*$/i,
23
+ "Fr." => /^\(*(fr\.*|friar)\)*$/i,
24
24
  "Master" => /^\(*(master)\)*$/i,
25
- "Sir" => /^\(*(sir)\)*$/i
25
+ "Sir" => /^\(*(sir)\)*$/i
26
26
  }
27
27
 
28
28
  SUFFIX = {
29
- "Sr." => /^\(*(sr\.|senior)\)*$/i,
30
- "Jr." => /^\(*(jr\.|junior)\)*$/i,
31
- "Esq." => /^\(*(esq\.|esquire)\)*$/i,
32
- "PhD." => /^\(*(phd\.)\)*$/i
29
+ "Sr." => /^\(*(sr\.|senior)\)*$/i,
30
+ "Jr." => /^\(*(jr\.|junior)\)*$/i,
31
+ "Esq." => /^\(*(esq\.|esquire)\)*$/i,
32
+ "Ph.D." => /^\(*(phd\.?)\)*$/i
33
33
  }
34
34
 
35
35
  SUFFIX_GENERATIONAL_ROMAN = /^\(*[IVX\.]+\)*$/i
36
36
  SUFFIX_ACADEMIC = /^(APR|RPh|MD|MA|DMD|DDS|PharmD|EngD|DPhil|JD|DD|DO|BA|BS|BSc|BE|BFA|MA|MS|MSc|MFA|MLA|MBA)$/i
37
37
  SUFFIX_PROFESSIONAL = /^(PE|CSA|CPA|CPL|CME|CEng|OFM|CSV|Douchebag)$/i
38
- SUFFIX_ABBREVIATION = /^[A-Z\.]+$/
38
+ SUFFIX_ABBREVIATION = /^[A-Z\.]+[A-Z\.]+$/ # It should be at least 2 letters
39
39
 
40
40
  LAST_NAME_PRE_DANGLERS = /^(vere|von|van|de|del|della|di|da|pietro|vanden|du|st|la|ter|ten)$/i
41
41
  LAST_NAME_PRE_CONCATS = /^(o'|o`|mc)$/i
@@ -128,7 +128,7 @@ module Nameable
128
128
  @last = "#{name[n-1]}-#{@last}"
129
129
  name[n-1] = nil
130
130
  else
131
- @middle = name[n]
131
+ @middle = @middle ? "#{name[n]} #{@middle}" : name[n]
132
132
  end
133
133
 
134
134
  name.delete_at(n)
@@ -140,7 +140,13 @@ module Nameable
140
140
 
141
141
  def parse(name)
142
142
  if name.class == String
143
- name = name.split(/\s+/)
143
+ if name.index(',')
144
+ name = "#{$2} #{$1}" if name =~ /^([a-z]+),(.*)/i
145
+
146
+ #name = "#{$2} #{$1}" if name =~ /^([a-z]+),(.*)/i
147
+ end
148
+
149
+ name = name.strip.split(/\s+/)
144
150
  end
145
151
 
146
152
  name = name.first.split(/[^[:alnum:]]+/) if name.size == 1 and name.first.split(/[^[:alnum:]]+/)
@@ -157,7 +163,7 @@ module Nameable
157
163
  end
158
164
 
159
165
  def to_s
160
- [@prefix, @first, @middle, @last, @suffix].compact.join(' ')
166
+ [@prefix, @first, @middle, @last].compact.join(' ') + (@suffix ? ", #{@suffix}" : "")
161
167
  end
162
168
 
163
169
  def to_name
@@ -165,7 +171,7 @@ module Nameable
165
171
  end
166
172
 
167
173
  def to_fullname
168
- [@prefix, @first, @middle, @last, @suffix].compact.join(' ')
174
+ to_s
169
175
  end
170
176
 
171
177
  def to_nameable
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nameable"
3
- s.version = "0.1.2"
4
- s.date = "2010-06-28"
3
+ s.version = "0.2.0"
4
+ s.date = "2010-07-12"
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"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nameable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Horn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-28 00:00:00 -04:00
18
+ date: 2010-07-12 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21