name_parse 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitconfig +6 -0
- data/AUTHORS +6 -0
- data/CHANGELOG +56 -0
- data/MANIFEST +25 -0
- data/README +34 -0
- data/Rakefile +69 -0
- data/lib/name_parse.rb +11 -0
- data/lib/name_parse/error.rb +4 -0
- data/lib/name_parse/parser.rb +91 -0
- data/lib/name_parse/version.rb +3 -0
- data/name_parse.gemspec +34 -0
- data/spec/helper.rb +20 -0
- data/spec/name_parse/parser.rb +120 -0
- data/tasks/authors.rake +30 -0
- data/tasks/bacon.rake +66 -0
- data/tasks/changelog.rake +18 -0
- data/tasks/copyright.rake +21 -0
- data/tasks/gem.rake +23 -0
- data/tasks/gem_installer.rake +76 -0
- data/tasks/install_dependencies.rake +6 -0
- data/tasks/manifest.rake +4 -0
- data/tasks/rcov.rake +23 -0
- data/tasks/release.rake +52 -0
- data/tasks/reversion.rake +8 -0
- data/tasks/setup.rake +14 -0
- data/tasks/yard.rake +4 -0
- metadata +120 -0
data/.gitconfig
ADDED
data/AUTHORS
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
[736bf3d | Thu May 07 16:54:52 UTC 2009] TJ Vanderpoel <bougyman@zero.(none)>
|
2
|
+
|
3
|
+
* completed refactoring to methodized matchers in #parse
|
4
|
+
|
5
|
+
[e58f6e4 | Thu May 07 16:29:25 UTC 2009] TJ Vanderpoel <bougyman@zero.(none)>
|
6
|
+
|
7
|
+
* continued to refacor into a methodized pattern for matching in #parse
|
8
|
+
|
9
|
+
[835e508 | Thu May 07 03:29:00 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
10
|
+
|
11
|
+
* ignore csv files
|
12
|
+
|
13
|
+
[fcb13a0 | Thu May 07 03:28:14 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
14
|
+
|
15
|
+
* added README as description
|
16
|
+
|
17
|
+
[016010c | Thu May 07 03:18:51 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
18
|
+
|
19
|
+
* Version 0.0.4
|
20
|
+
|
21
|
+
[5d85b44 | Thu May 07 03:14:31 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
22
|
+
|
23
|
+
* methodized when match target for first_name. TODO: make the other when matchers follow the same format
|
24
|
+
|
25
|
+
[09dee2a | Wed May 06 21:05:00 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
26
|
+
|
27
|
+
* Version 0.0.3
|
28
|
+
|
29
|
+
[9481b20 | Wed May 06 21:04:11 UTC 2009] Jayson Vaughn (thedonvaughn) <jayson.vaughn@gmail.com>
|
30
|
+
|
31
|
+
* added bacon task back from FSR, added Bacon.summary_on_exit to spec/helper.rb
|
32
|
+
|
33
|
+
[5c65ac6 | Wed May 06 20:25:18 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
34
|
+
|
35
|
+
* Version 0.0.2
|
36
|
+
|
37
|
+
[f34e13b | Wed May 06 20:09:19 UTC 2009] Jayson Vaughn (thedonvaughn) <jayson.vaughn@gmail.com>
|
38
|
+
|
39
|
+
* added handling of multiple last names
|
40
|
+
|
41
|
+
[fe9fbac | Wed May 06 18:41:19 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
42
|
+
|
43
|
+
* added more name types and yard task, docs at doc.rubyists.com/name_parse
|
44
|
+
|
45
|
+
[d901070 | Wed May 06 18:18:24 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
46
|
+
|
47
|
+
* added more name types, changed exception class to UnknownFormat for more descriptive error when we cannot parse a name
|
48
|
+
|
49
|
+
[a57d649 | Wed May 06 16:56:52 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
50
|
+
|
51
|
+
* added first 3 parse conditions
|
52
|
+
|
53
|
+
[d276663 | Wed May 06 15:55:33 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
54
|
+
|
55
|
+
* bare tree, ready to spec
|
56
|
+
|
data/MANIFEST
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
AUTHORS
|
2
|
+
CHANGELOG
|
3
|
+
MANIFEST
|
4
|
+
README
|
5
|
+
Rakefile
|
6
|
+
lib/name_parse.rb
|
7
|
+
lib/name_parse/error.rb
|
8
|
+
lib/name_parse/parser.rb
|
9
|
+
lib/name_parse/version.rb
|
10
|
+
name_parse.gemspec
|
11
|
+
spec/helper.rb
|
12
|
+
spec/name_parse/parser.rb
|
13
|
+
tasks/authors.rake
|
14
|
+
tasks/bacon.rake
|
15
|
+
tasks/changelog.rake
|
16
|
+
tasks/copyright.rake
|
17
|
+
tasks/gem.rake
|
18
|
+
tasks/gem_installer.rake
|
19
|
+
tasks/install_dependencies.rake
|
20
|
+
tasks/manifest.rake
|
21
|
+
tasks/rcov.rake
|
22
|
+
tasks/release.rake
|
23
|
+
tasks/reversion.rake
|
24
|
+
tasks/setup.rake
|
25
|
+
tasks/yard.rake
|
data/README
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
=========================================================
|
2
|
+
Name Parse
|
3
|
+
Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry)
|
4
|
+
Distributed under the terms of the MIT License.
|
5
|
+
==========================================================
|
6
|
+
|
7
|
+
About
|
8
|
+
-----
|
9
|
+
A ruby library for turning arbitrary name strings such as "Dr Helen Hunt", "Mr James T. Kirk" into a
|
10
|
+
standardized object usable as
|
11
|
+
parsed = NameParse::Parser.new("Dr Helen Hunt")
|
12
|
+
puts "%s %s" % [parsed.first, parsed.last]
|
13
|
+
|
14
|
+
|
15
|
+
Requirements
|
16
|
+
------------
|
17
|
+
- ruby (>= 1.8)
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
Example of using on a list:
|
23
|
+
|
24
|
+
bougyman@zero:~/git_checkouts/name_parse$ irb -r lib/name_parse
|
25
|
+
irb(main):001:0> list = ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"]
|
26
|
+
=> ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"]
|
27
|
+
irb(main):002:0> list.map { |n| p = NameParse[n]; [p.first, p.last] }
|
28
|
+
=> [["Jayson", "Vaughn"], ["Helen", "Hunt"], ["James", "Kirk"]]
|
29
|
+
|
30
|
+
|
31
|
+
Support
|
32
|
+
-------
|
33
|
+
Home page at http://github.com/bougyman/name_parse
|
34
|
+
#rubyists on FreeNode
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
begin; require 'rubygems'; rescue LoadError; end
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
require 'time'
|
7
|
+
require 'date'
|
8
|
+
require "lib/name_parse"
|
9
|
+
|
10
|
+
PROJECT_SPECS = FileList[
|
11
|
+
'spec/**/*.rb'
|
12
|
+
].reject { |h| h.match(/helper.rb/) }
|
13
|
+
|
14
|
+
PROJECT_MODULE = 'NameParse'
|
15
|
+
PROJECT_README = 'README'
|
16
|
+
#PROJECT_RUBYFORGE_GROUP_ID = 3034
|
17
|
+
PROJECT_COPYRIGHT = [
|
18
|
+
"# Copyright (c) #{Time.now.year} The Rubyists rubyists@rubyists.com",
|
19
|
+
"# Distributed under the terms of the MIT license."
|
20
|
+
]
|
21
|
+
|
22
|
+
# To release the monthly version do:
|
23
|
+
# $ PROJECT_VERSION=2009.03 rake release
|
24
|
+
IGNORE_FILES = [/\.gitignore/]
|
25
|
+
|
26
|
+
GEMSPEC = Gem::Specification.new{|s|
|
27
|
+
s.name = 'name_parse'
|
28
|
+
s.author = "TJ Vanderpoel"
|
29
|
+
s.summary = "Parse name strings into their constituent parts"
|
30
|
+
s.description = File.read("README")
|
31
|
+
s.email = 'bougy.man@gmail.com'
|
32
|
+
s.homepage = 'http://github.com/bougyman/name_parse'
|
33
|
+
s.platform = Gem::Platform::RUBY
|
34
|
+
s.version = (ENV['PROJECT_VERSION'] || Object.const_get(PROJECT_MODULE)::VERSION)
|
35
|
+
s.files = `git ls-files`.split("\n").sort.reject { |f| IGNORE_FILES.detect { |exp| f.match(exp) } }
|
36
|
+
s.has_rdoc = true
|
37
|
+
s.require_path = 'lib'
|
38
|
+
#s.bindir = "bin"
|
39
|
+
#s.executables = ["name_parse"]
|
40
|
+
s.rubyforge_project = "pastr"
|
41
|
+
|
42
|
+
s.post_install_message = <<MESSAGE.strip
|
43
|
+
============================================================
|
44
|
+
|
45
|
+
Thank you for installing Name Parse!
|
46
|
+
|
47
|
+
============================================================
|
48
|
+
MESSAGE
|
49
|
+
|
50
|
+
"Verify your install with"
|
51
|
+
'# name-parse "Dr. Phil Seuss, Jr."'
|
52
|
+
}
|
53
|
+
|
54
|
+
Dir['tasks/*.rake'].each{|f| import(f) }
|
55
|
+
|
56
|
+
task :default => [:bacon]
|
57
|
+
|
58
|
+
CLEAN.include %w[
|
59
|
+
**/.*.sw?
|
60
|
+
*.gem
|
61
|
+
.config
|
62
|
+
**/*~
|
63
|
+
**/{data.db,cache.yaml}
|
64
|
+
*.yaml
|
65
|
+
pkg
|
66
|
+
rdoc
|
67
|
+
ydoc
|
68
|
+
*coverage*
|
69
|
+
]
|
data/lib/name_parse.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module NameParse
|
2
|
+
class Parser
|
3
|
+
attr_reader :first, :last, :suffix, :prefix, :middle, :raw, :matched
|
4
|
+
attr_accessor :first_name_re, :last_name_re, :middle_name_re, :prefix_re
|
5
|
+
|
6
|
+
def initialize(name_string = nil, options = {})
|
7
|
+
@options = options
|
8
|
+
@last_name_re = @options[:last_name_re] || /(?:(?:v[ao]n(?:\s+der?)?|de\s+la)\s+)?\w[-.'\w]+/i
|
9
|
+
@middle_name_re = @options[:middle_name_re] || /\w(?:\.|[-.'\w]+)?/
|
10
|
+
@prefix_re = @options[:prefix_re] || /(?:c\/o|dr|mrs?|ms|miss|mister|sgt|cpt|cpl)\.?/i
|
11
|
+
@first_name_re = @options[:first_name_re] || /\w[-.'\w]+/
|
12
|
+
parse(name_string) if name_string
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(name)
|
16
|
+
@raw = name
|
17
|
+
case name
|
18
|
+
# just "Firstname Lastname"
|
19
|
+
when first_last
|
20
|
+
first_last($~)
|
21
|
+
# Catch names with prefixes, no comma
|
22
|
+
when pre_first_last
|
23
|
+
pre_first_last($~)
|
24
|
+
# Catch names with prefixes and middle names, no comma
|
25
|
+
when pre_first_mid_last
|
26
|
+
pre_first_mid_last($~)
|
27
|
+
# just "Firstname Middle Lastname"
|
28
|
+
when first_mid_last
|
29
|
+
first_mid_last($~)
|
30
|
+
# just "Lastname, Firstname (Middle)" middle is optional
|
31
|
+
when last_comma_first_mid
|
32
|
+
last_comma_first_mid($~)
|
33
|
+
# Comma with lots of lastnames, a first name, optional middle name
|
34
|
+
when multi_last_comma
|
35
|
+
multi_last_comma($~)
|
36
|
+
else
|
37
|
+
if @options[:raise_on_unknown]
|
38
|
+
raise UnknownFormat, "Could not parse #{@raw}"
|
39
|
+
else
|
40
|
+
@matched = :unknown
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
alias :first_name :first
|
47
|
+
|
48
|
+
def middle_i
|
49
|
+
return nil if middle.nil?
|
50
|
+
middle[0,1]
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def first_last(match = nil)
|
55
|
+
return %r{^(#{first_name_re})\s+(#{last_name_re})$} if match.nil?
|
56
|
+
@first, @last = match[1 .. 2]
|
57
|
+
@matched = :first_last
|
58
|
+
end
|
59
|
+
|
60
|
+
def pre_first_last(match = nil)
|
61
|
+
return %r{^(#{prefix_re})\s+(#{first_name_re})\s+(#{last_name_re})$} if match.nil?
|
62
|
+
@prefix, @first, @last = match[1 .. 3]
|
63
|
+
@matched = :pre_first_last
|
64
|
+
end
|
65
|
+
|
66
|
+
def pre_first_mid_last(match = nil)
|
67
|
+
return %r{^(#{prefix_re})\s+(#{first_name_re})\s+(#{middle_name_re})\s+(#{last_name_re})$} if match.nil?
|
68
|
+
@prefix, @first, @middle, @last = match[1 .. 4]
|
69
|
+
@matched = :pre_first_mid_last
|
70
|
+
end
|
71
|
+
|
72
|
+
def first_mid_last(match = nil)
|
73
|
+
return %r{^(#{first_name_re})\s+(#{middle_name_re})\s+(#{last_name_re})$} if match.nil?
|
74
|
+
@first, @middle, @last = match[1 .. 3]
|
75
|
+
@matched = :first_mid_last
|
76
|
+
end
|
77
|
+
|
78
|
+
def last_comma_first_mid(match = nil)
|
79
|
+
return %r{^(#{last_name_re}),(?:\s+)?(#{first_name_re})(?:\s+(#{middle_name_re}))?$} if match.nil?
|
80
|
+
@first, @last, @middle = match[2], match[1], match[3]
|
81
|
+
@matched = :last_comma_first_mid
|
82
|
+
end
|
83
|
+
|
84
|
+
def multi_last_comma(match = nil)
|
85
|
+
return %r{^((?:#{last_name_re}(?:\s+)?)+),(?:\s+)(#{first_name_re})(?:\s+(#{middle_name_re}))?$} if match.nil?
|
86
|
+
@first, @last, @middle = match[2], match[1], match[3]
|
87
|
+
@matched = :multi_last_comma
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
data/name_parse.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{name_parse}
|
5
|
+
s.version = "0.0.5"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["TJ Vanderpoel"]
|
9
|
+
s.date = %q{2009-05-07}
|
10
|
+
s.description = %q{========================================================= Name Parse Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry) Distributed under the terms of the MIT License. ========================================================== About ----- A ruby library for turning arbitrary name strings such as "Dr Helen Hunt", "Mr James T. Kirk" into a standardized object usable as parsed = NameParse::Parser.new("Dr Helen Hunt") puts "%s %s" % [parsed.first, parsed.last] Requirements ------------ - ruby (>= 1.8) Usage ----- Example of using on a list: bougyman@zero:~/git_checkouts/name_parse$ irb -r lib/name_parse irb(main):001:0> list = ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"] => ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"] irb(main):002:0> list.map { |n| p = NameParse[n]; [p.first, p.last] } => [["Jayson", "Vaughn"], ["Helen", "Hunt"], ["James", "Kirk"]] Support ------- Home page at http://github.com/bougyman/name_parse #rubyists on FreeNode}
|
11
|
+
s.email = %q{bougy.man@gmail.com}
|
12
|
+
s.files = ["AUTHORS", "CHANGELOG", "MANIFEST", "README", "Rakefile", "lib/name_parse.rb", "lib/name_parse/error.rb", "lib/name_parse/parser.rb", "lib/name_parse/version.rb", "name_parse.gemspec", "spec/helper.rb", "spec/name_parse/parser.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/copyright.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/rcov.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/yard.rake"]
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.homepage = %q{http://github.com/bougyman/name_parse}
|
15
|
+
s.post_install_message = %q{============================================================
|
16
|
+
|
17
|
+
Thank you for installing Name Parse!
|
18
|
+
|
19
|
+
============================================================}
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.rubyforge_project = %q{pastr}
|
22
|
+
s.rubygems_version = %q{1.3.1}
|
23
|
+
s.summary = %q{Parse name strings into their constituent parts}
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
else
|
31
|
+
end
|
32
|
+
else
|
33
|
+
end
|
34
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "pathname"
|
2
|
+
begin
|
3
|
+
require "bacon"
|
4
|
+
rescue LoadError
|
5
|
+
require "rubygems"
|
6
|
+
require "bacon"
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
if (local_path = Pathname.new(__FILE__).dirname.join("..", "lib", "name_parse.rb")).file?
|
11
|
+
require local_path
|
12
|
+
else
|
13
|
+
require "name_parse"
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
require "rubygems"
|
17
|
+
require "name_parse"
|
18
|
+
end
|
19
|
+
|
20
|
+
Bacon.summary_on_exit
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Copyright (c) 2009 The Rubyists rubyists@rubyists.com
|
2
|
+
# All files in this distribution are subject to the terms of the MIT license.
|
3
|
+
|
4
|
+
require 'spec/helper'
|
5
|
+
|
6
|
+
describe "Name Parser" do
|
7
|
+
|
8
|
+
|
9
|
+
it "Should Parse A First and Last Name Without Commas" do
|
10
|
+
name = NameParse["TJ Vanderpoel"]
|
11
|
+
name.first.should == "TJ"
|
12
|
+
name.last.should == "Vanderpoel"
|
13
|
+
name.matched.should == :first_last
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Should Parse A Standard Name With Commas" do
|
17
|
+
name = NameParse["Vanderpoel, T.J."]
|
18
|
+
name.first.should == "T.J."
|
19
|
+
name.last.should == "Vanderpoel"
|
20
|
+
name.matched.should == :last_comma_first_mid
|
21
|
+
end
|
22
|
+
|
23
|
+
it "Should Parse A First, Middle Initial, and Last Without Commas" do
|
24
|
+
name = NameParse["Tom J Rogers"]
|
25
|
+
name.first.should == "Tom"
|
26
|
+
name.middle.should == "J"
|
27
|
+
name.middle_i.should == "J"
|
28
|
+
name.last.should == "Rogers"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Should Parse A Prefix, First, Middle Initial (with period), and Last Without Commas" do
|
32
|
+
name = NameParse["Mr James T. Kirk"]
|
33
|
+
name.prefix.should == "Mr"
|
34
|
+
name.first.should == "James"
|
35
|
+
name.middle.should == "T."
|
36
|
+
name.middle_i.should == "T"
|
37
|
+
name.last.should == "Kirk"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should Parse A First, Middle Initial, and Last With Commas" do
|
41
|
+
name = NameParse["Rogers, Tom J"]
|
42
|
+
name.first.should == "Tom"
|
43
|
+
name.middle.should == "J"
|
44
|
+
name.middle_i.should == "J"
|
45
|
+
name.last.should == "Rogers"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "Should Parse A First, Middle Name, and Last Without Commas" do
|
49
|
+
name = NameParse["Tom James Rogers"]
|
50
|
+
name.first.should == "Tom"
|
51
|
+
name.middle.should == "James"
|
52
|
+
name.middle_i.should == "J"
|
53
|
+
name.last.should == "Rogers"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "Should Parse A First, Middle Name, and Last With Commas" do
|
57
|
+
name = NameParse["Rogers, Tom James"]
|
58
|
+
name.first.should == "Tom"
|
59
|
+
name.middle.should == "James"
|
60
|
+
name.middle_i.should == "J"
|
61
|
+
name.last.should == "Rogers"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "Should Parse A 'Von Something' Name Without Commas" do
|
65
|
+
name = NameParse["TJ Von Trapp"]
|
66
|
+
name.first.should == "TJ"
|
67
|
+
name.last.should == "Von Trapp"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "Should Parse A 'Von Something' Name With Commas" do
|
71
|
+
name = NameParse["Von Trapp, T.J."]
|
72
|
+
name.first.should == "T.J."
|
73
|
+
name.last.should == "Von Trapp"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "Should Parse A 'Van Something' Name Without Commas" do
|
77
|
+
name = NameParse["TJ Van Poel"]
|
78
|
+
name.first.should == "TJ"
|
79
|
+
name.last.should == "Van Poel"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "Should Parse A 'Van de Something' Name Without Commas" do
|
83
|
+
name = NameParse["TJ Van de Poel"]
|
84
|
+
name.first.should == "TJ"
|
85
|
+
name.last.should == "Van de Poel"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "Should Parse A 'Van der Something' Name Without Commas" do
|
89
|
+
name = NameParse["TJ Van der Poel"]
|
90
|
+
name.first.should == "TJ"
|
91
|
+
name.last.should == "Van der Poel"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "Should Parse A 'De la Something' Name Without Commas" do
|
95
|
+
name = NameParse["Oscar De la Hoya"]
|
96
|
+
name.first.should == "Oscar"
|
97
|
+
name.last.should == "De la Hoya"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "Should Parse A Doctor's Name" do
|
101
|
+
name = NameParse["Dr Phil Seuss"]
|
102
|
+
name.first.should == "Phil"
|
103
|
+
name.last.should == "Seuss"
|
104
|
+
name.prefix.should == "Dr"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "Should Parse a Name with C/O as Prefix" do
|
108
|
+
name = NameParse["C/O Chris Elrod"]
|
109
|
+
name.first.should == "Chris"
|
110
|
+
name.last.should == "Elrod"
|
111
|
+
name.prefix.should == "C/O"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "Should parse a 2 lastname name with a comma" do
|
115
|
+
name = NameParse["Alfredo Lorenzo, Frank"]
|
116
|
+
name.first.should == "Frank"
|
117
|
+
name.last.should == "Alfredo Lorenzo"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
data/tasks/authors.rake
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Once git has a fix for the glibc in handling .mailmap and another fix for
|
2
|
+
# allowing empty mail address to be mapped in .mailmap we won't have to handle
|
3
|
+
# them manually.
|
4
|
+
|
5
|
+
desc 'Update AUTHORS'
|
6
|
+
task :authors do
|
7
|
+
authors = Hash.new(0)
|
8
|
+
|
9
|
+
`git shortlog -nse`.scan(/(\d+)\s(.+)\s<(.*)>$/) do |count, name, email|
|
10
|
+
case name
|
11
|
+
when "bougyman"
|
12
|
+
name, email = "TJ Vanderpoel", "bougy.man@gmail.com"
|
13
|
+
when /riscfuture/i
|
14
|
+
name, email = "Tim Morgan", "riscfuture@gmail.com"
|
15
|
+
when "Michael Fellinger m.fellinger@gmail.com"
|
16
|
+
name, email = "Michael Fellinger", "m.fellinger@gmail.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
authors[[name, email]] += count.to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
File.open('AUTHORS', 'w+') do |io|
|
23
|
+
io.puts "Following persons have contributed to #{GEMSPEC.name}."
|
24
|
+
io.puts '(Sorted by number of submitted patches, then alphabetically)'
|
25
|
+
io.puts ''
|
26
|
+
authors.sort_by{|(n,e),c| [-c, n.downcase] }.each do |(name, email), count|
|
27
|
+
io.puts("%6d %s <%s>" % [count, name, email])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/tasks/bacon.rake
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
desc 'Run all bacon specs with pretty output'
|
2
|
+
task :bacon => :install_dependencies do
|
3
|
+
require 'open3'
|
4
|
+
require 'scanf'
|
5
|
+
require 'matrix'
|
6
|
+
|
7
|
+
specs = PROJECT_SPECS
|
8
|
+
|
9
|
+
some_failed = false
|
10
|
+
specs_size = specs.size
|
11
|
+
len = specs.map{|s| s.size }.sort.last
|
12
|
+
total_tests = total_assertions = total_failures = total_errors = 0
|
13
|
+
totals = Vector[0, 0, 0, 0]
|
14
|
+
|
15
|
+
red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m"
|
16
|
+
left_format = "%4d/%d: %-#{len + 11}s"
|
17
|
+
spec_format = "%d specifications (%d requirements), %d failures, %d errors"
|
18
|
+
|
19
|
+
specs.each_with_index do |spec, idx|
|
20
|
+
print(left_format % [idx + 1, specs_size, spec])
|
21
|
+
|
22
|
+
Open3.popen3(RUBY, spec) do |sin, sout, serr|
|
23
|
+
out = sout.read.strip
|
24
|
+
err = serr.read.strip
|
25
|
+
|
26
|
+
# this is conventional, see spec/innate/state/fiber.rb for usage
|
27
|
+
if out =~ /^Bacon::Error: (needed .*)/
|
28
|
+
puts(yellow % ("%6s %s" % ['', $1]))
|
29
|
+
else
|
30
|
+
total = nil
|
31
|
+
|
32
|
+
out.each_line do |line|
|
33
|
+
scanned = line.scanf(spec_format)
|
34
|
+
|
35
|
+
next unless scanned.size == 4
|
36
|
+
|
37
|
+
total = Vector[*scanned]
|
38
|
+
break
|
39
|
+
end
|
40
|
+
|
41
|
+
if total
|
42
|
+
totals += total
|
43
|
+
tests, assertions, failures, errors = total_array = total.to_a
|
44
|
+
|
45
|
+
if tests > 0 && failures + errors == 0
|
46
|
+
puts((green % "%6d passed") % tests)
|
47
|
+
else
|
48
|
+
some_failed = true
|
49
|
+
puts(red % " failed")
|
50
|
+
puts out unless out.empty?
|
51
|
+
puts err unless err.empty?
|
52
|
+
end
|
53
|
+
else
|
54
|
+
some_failed = true
|
55
|
+
puts(red % " failed")
|
56
|
+
puts out unless out.empty?
|
57
|
+
puts err unless err.empty?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
total_color = some_failed ? red : green
|
64
|
+
puts(total_color % (spec_format % totals.to_a))
|
65
|
+
exit 1 if some_failed
|
66
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
desc 'update changelog'
|
2
|
+
task :changelog do
|
3
|
+
File.open('CHANGELOG', 'w+') do |changelog|
|
4
|
+
`git log -z --abbrev-commit`.split("\0").each do |commit|
|
5
|
+
next if commit =~ /^Merge: \d*/
|
6
|
+
ref, author, time, _, title, _, message = commit.split("\n", 7)
|
7
|
+
ref = ref[/commit ([0-9a-f]+)/, 1]
|
8
|
+
author = author[/Author: (.*)/, 1].strip
|
9
|
+
time = Time.parse(time[/Date: (.*)/, 1]).utc
|
10
|
+
title.strip!
|
11
|
+
|
12
|
+
changelog.puts "[#{ref} | #{time}] #{author}"
|
13
|
+
changelog.puts '', " * #{title}"
|
14
|
+
changelog.puts '', message.rstrip if message
|
15
|
+
changelog.puts
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
desc "add copyright to all .rb files in the distribution"
|
2
|
+
task :copyright do
|
3
|
+
ignore = File.readlines('doc/LEGAL').
|
4
|
+
select{|line| line.strip!; File.exist?(line)}.
|
5
|
+
map{|file| File.expand_path(file)}
|
6
|
+
|
7
|
+
puts "adding copyright to files that don't have it currently"
|
8
|
+
puts PROJECT_COPYRIGHT
|
9
|
+
puts
|
10
|
+
|
11
|
+
Dir['{lib,test}/**/*{.rb}'].each do |file|
|
12
|
+
file = File.expand_path(file)
|
13
|
+
next if ignore.include? file
|
14
|
+
lines = File.readlines(file).map{|l| l.chomp}
|
15
|
+
unless lines.first(PROJECT_COPYRIGHT.size) == PROJECT_COPYRIGHT
|
16
|
+
puts "#{file} seems to need attention, first 4 lines:"
|
17
|
+
puts lines[0..3]
|
18
|
+
puts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
desc "make a gemspec"
|
4
|
+
task :gemspec => [:manifest, :changelog, :authors] do
|
5
|
+
gemspec_file = "#{GEMSPEC.name}.gemspec"
|
6
|
+
File.open(gemspec_file, 'w+'){|gs| gs.puts(GEMSPEC.to_ruby) }
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "package and install from gemspec"
|
10
|
+
task :install => [:gemspec] do
|
11
|
+
sh "gem build #{GEMSPEC.name}.gemspec"
|
12
|
+
sh "gem install #{GEMSPEC.name}-#{GEMSPEC.version}.gem"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "uninstall the gem"
|
16
|
+
task :uninstall => [:clean] do
|
17
|
+
sh %{gem uninstall -x #{GEMSPEC.name}}
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::GemPackageTask.new(GEMSPEC) do |p|
|
21
|
+
p.need_tar = true
|
22
|
+
p.need_zip = true
|
23
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
task :gem_installer do
|
2
|
+
class GemInstaller
|
3
|
+
def initialize(options = {}, &block)
|
4
|
+
@gems = []
|
5
|
+
@options = options
|
6
|
+
|
7
|
+
run(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(&block)
|
11
|
+
instance_eval(&block) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def gem(name, version = nil, options = {})
|
15
|
+
if version.respond_to?(:merge!)
|
16
|
+
options = version
|
17
|
+
else
|
18
|
+
options[:version] = version
|
19
|
+
end
|
20
|
+
|
21
|
+
@gems << [name, options]
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_gemspec(gemspec)
|
25
|
+
gemspec.dependencies.each do |dependency|
|
26
|
+
dependency.version_requirements.as_list.each do |version|
|
27
|
+
gem(dependency.name, version)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
setup
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
require 'rubygems'
|
36
|
+
require 'rubygems/dependency_installer'
|
37
|
+
|
38
|
+
@gems.each do |name, options|
|
39
|
+
setup_gem(name, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_gem(name, options, try_install = true)
|
44
|
+
print "activating #{name} ... "
|
45
|
+
Gem.activate(name, *[options[:version]].compact)
|
46
|
+
require(options[:lib] || name)
|
47
|
+
puts "success."
|
48
|
+
rescue LoadError => error
|
49
|
+
puts error
|
50
|
+
install_gem(name, options) if try_install
|
51
|
+
setup_gem(name, options, try_install = false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def install_gem(name, options)
|
55
|
+
installer = Gem::DependencyInstaller.new(options)
|
56
|
+
|
57
|
+
temp_argv(options[:extconf]) do
|
58
|
+
print "Installing #{name} ... "
|
59
|
+
installer.install(name, options[:version])
|
60
|
+
puts "done."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def temp_argv(extconf)
|
65
|
+
if extconf ||= @options[:extconf]
|
66
|
+
old_argv = ARGV.clone
|
67
|
+
ARGV.replace(extconf.split(' '))
|
68
|
+
end
|
69
|
+
|
70
|
+
yield
|
71
|
+
|
72
|
+
ensure
|
73
|
+
ARGV.replace(old_argv) if extconf
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/tasks/manifest.rake
ADDED
data/tasks/rcov.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
desc 'code coverage'
|
2
|
+
task :rcov => :clean do
|
3
|
+
specs = PROJECT_SPECS
|
4
|
+
|
5
|
+
ignore = %w[ gem rack bacon innate hpricot nagoro/lib/nagoro ]
|
6
|
+
|
7
|
+
if RUBY_VERSION >= '1.8.7'
|
8
|
+
ignore << 'begin_with' << 'end_with'
|
9
|
+
end
|
10
|
+
if RUBY_VERSION < '1.9'
|
11
|
+
ignore << 'fiber'
|
12
|
+
end
|
13
|
+
|
14
|
+
ignored = ignore.join(',')
|
15
|
+
|
16
|
+
cmd = "rcov --aggregate coverage.data --sort coverage -t --%s -x '#{ignored}' %s"
|
17
|
+
|
18
|
+
while spec = specs.shift
|
19
|
+
puts '', "Gather coverage for #{spec} ..."
|
20
|
+
html = specs.empty? ? 'html' : 'no-html'
|
21
|
+
sh(cmd % [html, spec])
|
22
|
+
end
|
23
|
+
end
|
data/tasks/release.rake
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
namespace :release do
|
2
|
+
task :all => [:release_github, :release_rubyforge]
|
3
|
+
|
4
|
+
desc 'Display instructions to release on github'
|
5
|
+
task :github => [:reversion, :gemspec] do
|
6
|
+
name, version = GEMSPEC.name, GEMSPEC.version
|
7
|
+
|
8
|
+
puts <<INSTRUCTIONS
|
9
|
+
First add the relevant files:
|
10
|
+
|
11
|
+
git add AUTHORS MANIFEST CHANGELOG #{name}.gemspec lib/#{name}/version.rb
|
12
|
+
|
13
|
+
Then commit them, tag the commit, and push:
|
14
|
+
|
15
|
+
git commit -m 'Version #{version}'
|
16
|
+
git tag -a -m '#{version}' '#{version}'
|
17
|
+
git push
|
18
|
+
|
19
|
+
INSTRUCTIONS
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: Not tested
|
24
|
+
desc 'Display instructions to release on rubyforge'
|
25
|
+
task :rubyforge => [:reversion, :gemspec, :package] do
|
26
|
+
name, version = GEMSPEC.name, GEMSPEC.version
|
27
|
+
|
28
|
+
puts <<INSTRUCTIONS
|
29
|
+
To publish to rubyforge do following:
|
30
|
+
|
31
|
+
rubyforge login
|
32
|
+
rubyforge add_release #{name} #{name} '#{version}' pkg/#{name}-#{version}.gem
|
33
|
+
|
34
|
+
After you have done these steps, see:
|
35
|
+
|
36
|
+
rake release:rubyforge_archives
|
37
|
+
|
38
|
+
INSTRUCTIONS
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Display instructions to add archives after release:rubyforge'
|
42
|
+
task :rubyforge_archives do
|
43
|
+
name, version = GEMSPEC.name, GEMSPEC.version
|
44
|
+
puts "Adding archives for distro packagers is:", ""
|
45
|
+
|
46
|
+
Dir["pkg/#{name}-#{version}.{tgz,zip}"].each do |file|
|
47
|
+
puts "rubyforge add_file #{name} #{name} '#{version}' '#{file}'"
|
48
|
+
end
|
49
|
+
|
50
|
+
puts
|
51
|
+
end
|
52
|
+
end
|
data/tasks/setup.rake
ADDED
data/tasks/yard.rake
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: name_parse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TJ Vanderpoel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-01 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |
|
17
|
+
=========================================================
|
18
|
+
Name Parse
|
19
|
+
Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry)
|
20
|
+
Distributed under the terms of the MIT License.
|
21
|
+
==========================================================
|
22
|
+
|
23
|
+
About
|
24
|
+
-----
|
25
|
+
A ruby library for turning arbitrary name strings such as "Dr Helen Hunt", "Mr James T. Kirk" into a
|
26
|
+
standardized object usable as
|
27
|
+
parsed = NameParse::Parser.new("Dr Helen Hunt")
|
28
|
+
puts "%s %s" % [parsed.first, parsed.last]
|
29
|
+
|
30
|
+
|
31
|
+
Requirements
|
32
|
+
------------
|
33
|
+
- ruby (>= 1.8)
|
34
|
+
|
35
|
+
Usage
|
36
|
+
-----
|
37
|
+
|
38
|
+
Example of using on a list:
|
39
|
+
|
40
|
+
bougyman@zero:~/git_checkouts/name_parse$ irb -r lib/name_parse
|
41
|
+
irb(main):001:0> list = ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"]
|
42
|
+
=> ["Jayson Vaughn", "Dr Helen Hunt", "Mr James T. Kirk"]
|
43
|
+
irb(main):002:0> list.map { |n| p = NameParse[n]; [p.first, p.last] }
|
44
|
+
=> [["Jayson", "Vaughn"], ["Helen", "Hunt"], ["James", "Kirk"]]
|
45
|
+
|
46
|
+
|
47
|
+
Support
|
48
|
+
-------
|
49
|
+
Home page at http://github.com/bougyman/name_parse
|
50
|
+
#rubyists on FreeNode
|
51
|
+
|
52
|
+
email: bougy.man@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitconfig
|
61
|
+
- AUTHORS
|
62
|
+
- CHANGELOG
|
63
|
+
- MANIFEST
|
64
|
+
- README
|
65
|
+
- Rakefile
|
66
|
+
- lib/name_parse.rb
|
67
|
+
- lib/name_parse/error.rb
|
68
|
+
- lib/name_parse/parser.rb
|
69
|
+
- lib/name_parse/version.rb
|
70
|
+
- name_parse.gemspec
|
71
|
+
- spec/helper.rb
|
72
|
+
- spec/name_parse/parser.rb
|
73
|
+
- tasks/authors.rake
|
74
|
+
- tasks/bacon.rake
|
75
|
+
- tasks/changelog.rake
|
76
|
+
- tasks/copyright.rake
|
77
|
+
- tasks/gem.rake
|
78
|
+
- tasks/gem_installer.rake
|
79
|
+
- tasks/install_dependencies.rake
|
80
|
+
- tasks/manifest.rake
|
81
|
+
- tasks/rcov.rake
|
82
|
+
- tasks/release.rake
|
83
|
+
- tasks/reversion.rake
|
84
|
+
- tasks/setup.rake
|
85
|
+
- tasks/yard.rake
|
86
|
+
has_rdoc: true
|
87
|
+
homepage: http://github.com/bougyman/name_parse
|
88
|
+
licenses: []
|
89
|
+
|
90
|
+
post_install_message: |-
|
91
|
+
============================================================
|
92
|
+
|
93
|
+
Thank you for installing Name Parse!
|
94
|
+
|
95
|
+
============================================================
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: "0"
|
105
|
+
version:
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
version:
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project: pastr
|
115
|
+
rubygems_version: 1.3.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Parse name strings into their constituent parts
|
119
|
+
test_files: []
|
120
|
+
|