bougyman-name_parse 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +5 -0
- data/CHANGELOG +28 -0
- data/MANIFEST +25 -0
- data/README +34 -0
- data/Rakefile +69 -0
- data/lib/name_parse/error.rb +4 -0
- data/lib/name_parse/parser.rb +65 -0
- data/lib/name_parse/version.rb +3 -0
- data/lib/name_parse.rb +11 -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 +82 -0
data/AUTHORS
ADDED
data/CHANGELOG
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[9481b20 | Wed May 06 21:04:11 UTC 2009] Jayson Vaughn (thedonvaughn) <jayson.vaughn@gmail.com>
|
|
2
|
+
|
|
3
|
+
* added bacon task back from FSR, added Bacon.summary_on_exit to spec/helper.rb
|
|
4
|
+
|
|
5
|
+
[5c65ac6 | Wed May 06 20:25:18 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
|
6
|
+
|
|
7
|
+
* Version 0.0.2
|
|
8
|
+
|
|
9
|
+
[f34e13b | Wed May 06 20:09:19 UTC 2009] Jayson Vaughn (thedonvaughn) <jayson.vaughn@gmail.com>
|
|
10
|
+
|
|
11
|
+
* added handling of multiple last names
|
|
12
|
+
|
|
13
|
+
[fe9fbac | Wed May 06 18:41:19 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
|
14
|
+
|
|
15
|
+
* added more name types and yard task, docs at doc.rubyists.com/name_parse
|
|
16
|
+
|
|
17
|
+
[d901070 | Wed May 06 18:18:24 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
|
18
|
+
|
|
19
|
+
* added more name types, changed exception class to UnknownFormat for more descriptive error when we cannot parse a name
|
|
20
|
+
|
|
21
|
+
[a57d649 | Wed May 06 16:56:52 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
|
22
|
+
|
|
23
|
+
* added first 3 parse conditions
|
|
24
|
+
|
|
25
|
+
[d276663 | Wed May 06 15:55:33 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
|
26
|
+
|
|
27
|
+
* bare tree, ready to spec
|
|
28
|
+
|
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 = s.summary
|
|
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'] || Date.today.strftime("%Y.%m.%d"))
|
|
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
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module NameParse
|
|
2
|
+
class Parser
|
|
3
|
+
attr_reader :first, :last, :suffix, :prefix, :middle, :raw, :matched
|
|
4
|
+
|
|
5
|
+
def initialize(name_string = nil)
|
|
6
|
+
@raw = name_string
|
|
7
|
+
parse(@raw) if @raw
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def prefix_re
|
|
11
|
+
/(?:c\/o|dr|mrs?|ms|miss|mister|sgt|cpt|cpl)\.?/i
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def first_name_re
|
|
15
|
+
/\w[-.'\w]+/
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def last_name_re
|
|
19
|
+
/(?:(?:v[ao]n(?:\s+der?)?|de\s+la)\s+)?\w[-.'\w]+/i
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def middle_name_re
|
|
23
|
+
/\w(?:\.|[-.'\w]+)?/
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def middle_i
|
|
27
|
+
return nil if middle.nil?
|
|
28
|
+
middle[0,1]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def parse(name)
|
|
32
|
+
case name
|
|
33
|
+
# just "Firstname Lastname"
|
|
34
|
+
when /^(#{first_name_re})\s+(#{last_name_re})$/
|
|
35
|
+
@first, @last = $1, $2
|
|
36
|
+
@matched = :first_last
|
|
37
|
+
# Catch names with prefixes, no comma
|
|
38
|
+
when /^(#{prefix_re})\s+(#{first_name_re})\s+(#{last_name_re})$/
|
|
39
|
+
@prefix, @first, @last = $1, $2, $3
|
|
40
|
+
@matched = :pre_first_last
|
|
41
|
+
# Catch names with prefixes and middle names, no comma
|
|
42
|
+
when /^(#{prefix_re})\s+(#{first_name_re})\s+(#{middle_name_re})\s+(#{last_name_re})$/
|
|
43
|
+
@prefix, @first, @middle, @last = $1, $2, $3, $4
|
|
44
|
+
@matched = :pre_first_mid_last
|
|
45
|
+
# just "Firstname Middle Lastname"
|
|
46
|
+
when /^(#{first_name_re})\s+(#{middle_name_re})\s+(#{last_name_re})$/
|
|
47
|
+
@first, @middle, @last = $1, $2, $3
|
|
48
|
+
@matched = :first_mid_last
|
|
49
|
+
# just "Lastname, Firstname (Middle)" middle is optional
|
|
50
|
+
when /^(#{last_name_re}),(?:\s+)?(#{first_name_re})(?:\s+(#{middle_name_re}))?$/
|
|
51
|
+
@first, @last, @middle = $2, $1, $3
|
|
52
|
+
@matched = :last_comma_first_mid
|
|
53
|
+
# Comma with lots of lastnames, a first name, optional middle name
|
|
54
|
+
when /^((?:#{last_name_re}(?:\s+)?)+),(?:\s+)(#{first_name_re})(?:\s+(#{middle_name_re}))?$/
|
|
55
|
+
@first, @last, @middle = $2, $1, $3
|
|
56
|
+
@matched = :multi_last_comma
|
|
57
|
+
else
|
|
58
|
+
raise UnknownFormat, "Could not parse #{@raw_name}"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
alias :first_name :first
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/name_parse.rb
ADDED
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.3"
|
|
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-06}
|
|
10
|
+
s.description = %q{Parse name strings into their constituent parts}
|
|
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,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bougyman-name_parse
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- TJ Vanderpoel
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-05-06 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Parse name strings into their constituent parts
|
|
17
|
+
email: bougy.man@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- AUTHORS
|
|
26
|
+
- CHANGELOG
|
|
27
|
+
- MANIFEST
|
|
28
|
+
- README
|
|
29
|
+
- Rakefile
|
|
30
|
+
- lib/name_parse.rb
|
|
31
|
+
- lib/name_parse/error.rb
|
|
32
|
+
- lib/name_parse/parser.rb
|
|
33
|
+
- lib/name_parse/version.rb
|
|
34
|
+
- name_parse.gemspec
|
|
35
|
+
- spec/helper.rb
|
|
36
|
+
- spec/name_parse/parser.rb
|
|
37
|
+
- tasks/authors.rake
|
|
38
|
+
- tasks/bacon.rake
|
|
39
|
+
- tasks/changelog.rake
|
|
40
|
+
- tasks/copyright.rake
|
|
41
|
+
- tasks/gem.rake
|
|
42
|
+
- tasks/gem_installer.rake
|
|
43
|
+
- tasks/install_dependencies.rake
|
|
44
|
+
- tasks/manifest.rake
|
|
45
|
+
- tasks/rcov.rake
|
|
46
|
+
- tasks/release.rake
|
|
47
|
+
- tasks/reversion.rake
|
|
48
|
+
- tasks/setup.rake
|
|
49
|
+
- tasks/yard.rake
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: http://github.com/bougyman/name_parse
|
|
52
|
+
post_install_message: |-
|
|
53
|
+
============================================================
|
|
54
|
+
|
|
55
|
+
Thank you for installing Name Parse!
|
|
56
|
+
|
|
57
|
+
============================================================
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: "0"
|
|
67
|
+
version:
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: "0"
|
|
73
|
+
version:
|
|
74
|
+
requirements: []
|
|
75
|
+
|
|
76
|
+
rubyforge_project: pastr
|
|
77
|
+
rubygems_version: 1.2.0
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 2
|
|
80
|
+
summary: Parse name strings into their constituent parts
|
|
81
|
+
test_files: []
|
|
82
|
+
|