dburkes-people_places_things 1.0.0
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/README.rdoc +38 -0
- data/spec/ansi_counties_spec.rb +27 -0
- data/spec/helper.rb +1 -0
- data/spec/person_name_spec.rb +182 -0
- data/spec/street_address_spec.rb +159 -0
- metadata +57 -0
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PeoplePlacesThings
|
2
|
+
=
|
3
|
+
PeoplePlacesThings is a collection of ruby classes for parsing and formatting U.S person names, street addresses, phone numbers, and more.
|
4
|
+
|
5
|
+
Using PeoplePlacesThings
|
6
|
+
=
|
7
|
+
require 'people_places_things'
|
8
|
+
|
9
|
+
name = PersonName.parse("george quincy harold peabody jr.")
|
10
|
+
name.first => "george"
|
11
|
+
name.first_i => "g"
|
12
|
+
name.last => "peabody"
|
13
|
+
name.middle => "quincy harold"
|
14
|
+
name.suffix => "jr."
|
15
|
+
name.to_s(:last_comma_first) => "peabody,george"
|
16
|
+
name.to_s(:full) => "george quincy peabody jr."
|
17
|
+
|
18
|
+
name2 = PersonName.parse("peabody jr., george quincy harold", :last_first_middle)
|
19
|
+
name.eql?(name2) => true
|
20
|
+
|
21
|
+
addr = StreetAddress.parse("204-b ne. 1st ave suite 4")
|
22
|
+
addr.number => "204-b"
|
23
|
+
addr.pre_direction => :northeast
|
24
|
+
addr.name => "1st"
|
25
|
+
addr.suffix => :avenue
|
26
|
+
addr.unit_type => :suite
|
27
|
+
addr.unit => "4"
|
28
|
+
addr.to_s => "204-b northeast 1st avenue suite 4"
|
29
|
+
|
30
|
+
ANSICounties.code_for('GA', 'FULTON') => 13121
|
31
|
+
ANSICounties.code_for(:state => 'ga', :county => 'fulton') => 13121
|
32
|
+
ANSICounties.data_for(13121) => { :state => 'GA', :county => 'FULTON' }
|
33
|
+
|
34
|
+
Data source
|
35
|
+
=
|
36
|
+
The data that makes up `lib/people_places_things/ansi_counties/data/data.yml` was generated from `lib/people_places_things/ansi_counties/data/raw.txt`, which was downloaded from [the US Census website](http://www.census.gov/geo/www/ansi/download.html).
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe ANSICounties do
|
4
|
+
it "should find code for valid state and county" do
|
5
|
+
ANSICounties.code_for('ga', 'fulton').should == 13121
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should find code for valid state and county hash" do
|
9
|
+
ANSICounties.code_for(:state => 'ga', :county => 'fulton').should == 13121
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return nil for invalid state and county" do
|
13
|
+
ANSICounties.code_for(:state => 'ga', :county => 'fubar').should == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find code for alternate st. form" do
|
17
|
+
ANSICounties.code_for(:state => 'MO', :county => 'saint LOUIS').should == 29510
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should find data for valid code" do
|
21
|
+
ANSICounties.data_for(13121).should == { :state => 'GA', :county => 'FULTON' }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return nil for invalid code" do
|
25
|
+
ANSICounties.data_for(1312111).should == nil
|
26
|
+
end
|
27
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lib/people_places_things'
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe PersonName do
|
4
|
+
it "should parse first_middle_last" do
|
5
|
+
name = PersonName.parse "george quincy drake peabody", :first_middle_last
|
6
|
+
name.first.should == 'george'
|
7
|
+
name.middle.should == 'quincy drake'
|
8
|
+
name.last.should == 'peabody'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse last_first_middle" do
|
12
|
+
name = PersonName.parse "peabody george quincy drake", :last_first_middle
|
13
|
+
name.first.should == 'george'
|
14
|
+
name.middle.should == 'quincy drake'
|
15
|
+
name.last.should == 'peabody'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse last only in first_middle_last format" do
|
19
|
+
name = PersonName.parse "peabody", :first_middle_last
|
20
|
+
name.first.should == nil
|
21
|
+
name.middle.should == nil
|
22
|
+
name.last.should == 'peabody'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse last only in last_first_middle format" do
|
26
|
+
name = PersonName.parse "peabody", :last_first_middle
|
27
|
+
name.first.should == nil
|
28
|
+
name.middle.should == nil
|
29
|
+
name.last.should == 'peabody'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should parse first middle last suffix" do
|
33
|
+
name = PersonName.parse "george f. peabody jr"
|
34
|
+
name.first.should == 'george'
|
35
|
+
name.middle.should == 'f.'
|
36
|
+
name.last.should == 'peabody'
|
37
|
+
name.suffix.should == 'jr'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should parse last suffix first middle" do
|
41
|
+
name = PersonName.parse "peabody jr george f.", :last_first_middle
|
42
|
+
name.first.should == 'george'
|
43
|
+
name.middle.should == 'f.'
|
44
|
+
name.last.should == 'peabody'
|
45
|
+
name.suffix.should == 'jr'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should default to first_middle_last" do
|
49
|
+
name = PersonName.parse "george quincy drake peabody"
|
50
|
+
name.first.should == 'george'
|
51
|
+
name.middle.should == 'quincy drake'
|
52
|
+
name.last.should == 'peabody'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should ignore spaces and commas" do
|
56
|
+
name = PersonName.parse " peabody,george quincy drake ", :last_first_middle
|
57
|
+
name.first.should == 'george'
|
58
|
+
name.middle.should == 'quincy drake'
|
59
|
+
name.last.should == 'peabody'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should strip periods from initials" do
|
63
|
+
name = PersonName.parse "george f. peabody", :first_middle_last
|
64
|
+
name.first.should == 'george'
|
65
|
+
name.middle.should == 'f.'
|
66
|
+
name.middle_i == 'f'
|
67
|
+
name.last.should == 'peabody'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should format for :first" do
|
71
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
72
|
+
name.to_s(:first).should == 'george'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should format for :middle" do
|
76
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
77
|
+
name.to_s(:middle).should == 'quincy'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should format for :last" do
|
81
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
82
|
+
name.to_s(:last).should == 'peabody'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should format for :full" do
|
86
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
87
|
+
name.to_s(:full).should == 'george quincy peabody'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should format for :full_reverse" do
|
91
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody', :suffix => 'jr.'
|
92
|
+
name.to_s(:full_reverse).should == 'peabody george quincy jr.'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should format for :first_space_last" do
|
96
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
97
|
+
name.to_s(:first_space_last).should == 'george peabody'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should format for :last_space_first" do
|
101
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
102
|
+
name.to_s(:last_space_first).should == 'peabody george'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should format for :last_comma_first" do
|
106
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
107
|
+
name.to_s(:last_comma_first).should == 'peabody,george'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should format for :last_comma_space_first" do
|
111
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
112
|
+
name.to_s(:last_comma_space_first).should == 'peabody, george'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should handle missing parts when formatting" do
|
116
|
+
PersonName.new({ :last => 'peabody' }).to_s(:last_comma_space_first).should == 'peabody'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should respond to index method" do
|
120
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
121
|
+
name[:first].should == 'george'
|
122
|
+
name[:middle].should == 'quincy'
|
123
|
+
name[:last].should == 'peabody'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should respond to individual accessors" do
|
127
|
+
name = PersonName.new :first => 'george', :middle => 'quincy', :last => 'peabody'
|
128
|
+
name.first.should == 'george'
|
129
|
+
name.first_i.should == 'g'
|
130
|
+
name.middle.should == 'quincy'
|
131
|
+
name.middle_i.should == 'q'
|
132
|
+
name.last.should == 'peabody'
|
133
|
+
name.last_i.should == 'p'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should recognize exact equality" do
|
137
|
+
PersonName.parse("george quincy peabody").should be_eql(PersonName.parse("george quincy peabody"))
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should ignore case for equality" do
|
141
|
+
PersonName.parse("george quincy peabody").should be_eql(PersonName.parse("george quincy PEABODY"))
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should recognize subset equality" do
|
145
|
+
PersonName.parse("george quincy peabody").should be_eql(PersonName.parse("george peabody"))
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should parse mc donald for first_middle_last" do
|
149
|
+
name = PersonName.parse "george quincy drake mc donald", :first_middle_last
|
150
|
+
name.first.should == 'george'
|
151
|
+
name.middle.should == 'quincy drake'
|
152
|
+
name.last.should == 'mcdonald'
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should parse mc donald for last_first_middle" do
|
156
|
+
name = PersonName.parse "mc donald george quincy drake", :last_first_middle
|
157
|
+
name.first.should == 'george'
|
158
|
+
name.middle.should == 'quincy drake'
|
159
|
+
name.last.should == 'mcdonald'
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should normalize suffixes" do
|
163
|
+
name = PersonName.parse "george quincy peabody jr"
|
164
|
+
name2 = PersonName.parse "peabody jr., george quincy", :last_first_middle
|
165
|
+
name.should be_eql(name2)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should support auto detect formatting for first_middle_last" do
|
169
|
+
name = PersonName.parse "george f. peabody jr"
|
170
|
+
name.first.should == 'george'
|
171
|
+
name.middle.should == 'f.'
|
172
|
+
name.last.should == 'peabody'
|
173
|
+
name.suffix.should == 'jr'
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should support auto detect formatting for last_first_middle" do
|
177
|
+
name = PersonName.parse "peabody, george quincy drake"
|
178
|
+
name.first.should == 'george'
|
179
|
+
name.middle.should == 'quincy drake'
|
180
|
+
name.last.should == 'peabody'
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe StreetAddress do
|
4
|
+
it "should parse number street" do
|
5
|
+
addr = StreetAddress.parse "123 Main Street"
|
6
|
+
addr.number.should == '123'
|
7
|
+
addr.name.should == 'Main'
|
8
|
+
addr.suffix.should == :street
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse number with letter" do
|
12
|
+
addr = StreetAddress.parse "204-B Main Street"
|
13
|
+
addr.number.should == '204-B'
|
14
|
+
addr.name.should == 'Main'
|
15
|
+
addr.suffix.should == :street
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse pre direction" do
|
19
|
+
addr = StreetAddress.parse "123 E Main Street"
|
20
|
+
addr.number.should == '123'
|
21
|
+
addr.pre_direction.should == :east
|
22
|
+
addr.name.should == 'Main'
|
23
|
+
addr.suffix.should == :street
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should parse post direction" do
|
27
|
+
addr = StreetAddress.parse "123 Main Street NE"
|
28
|
+
addr.number.should == '123'
|
29
|
+
addr.name.should == 'Main'
|
30
|
+
addr.suffix.should == :street
|
31
|
+
addr.post_direction.should == :northeast
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should parse pre and post direction" do
|
35
|
+
addr = StreetAddress.parse "123 E Main Street North"
|
36
|
+
addr.number.should == '123'
|
37
|
+
addr.pre_direction.should == :east
|
38
|
+
addr.name.should == 'Main'
|
39
|
+
addr.suffix.should == :street
|
40
|
+
addr.post_direction.should == :north
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should parse street names that look like directions" do
|
44
|
+
addr = StreetAddress.parse "123 E E St"
|
45
|
+
addr.number.should == '123'
|
46
|
+
addr.pre_direction.should == :east
|
47
|
+
addr.name.should == 'E'
|
48
|
+
addr.suffix.should == :street
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should parse street names that look like directions, with post directions" do
|
52
|
+
addr = StreetAddress.parse "123 E E St NE"
|
53
|
+
addr.number.should == '123'
|
54
|
+
addr.pre_direction.should == :east
|
55
|
+
addr.name.should == 'E'
|
56
|
+
addr.suffix.should == :street
|
57
|
+
addr.post_direction.should == :northeast
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should parse abbreviations" do
|
61
|
+
addr = StreetAddress.parse "123 e. 1st ave"
|
62
|
+
addr.number.should == '123'
|
63
|
+
addr.pre_direction.should == :east
|
64
|
+
addr.name.should == '1st'
|
65
|
+
addr.suffix.should == :avenue
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should parse suites" do
|
69
|
+
addr = StreetAddress.parse "123 E E St NE Ste 23"
|
70
|
+
addr.number.should == '123'
|
71
|
+
addr.pre_direction.should == :east
|
72
|
+
addr.name.should == 'E'
|
73
|
+
addr.suffix.should == :street
|
74
|
+
addr.post_direction.should == :northeast
|
75
|
+
addr.unit_type.should == :suite
|
76
|
+
addr.unit.should == '23'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should parse apartments" do
|
80
|
+
addr = StreetAddress.parse "123 E E St NE Apartment 4"
|
81
|
+
addr.number.should == '123'
|
82
|
+
addr.pre_direction.should == :east
|
83
|
+
addr.name.should == 'E'
|
84
|
+
addr.suffix.should == :street
|
85
|
+
addr.post_direction.should == :northeast
|
86
|
+
addr.unit_type.should == :apartment
|
87
|
+
addr.unit.should == '4'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should parse numbers" do
|
91
|
+
addr = StreetAddress.parse '123 E E St NE # 5'
|
92
|
+
addr.number.should == '123'
|
93
|
+
addr.pre_direction.should == :east
|
94
|
+
addr.name.should == 'E'
|
95
|
+
addr.suffix.should == :street
|
96
|
+
addr.post_direction.should == :northeast
|
97
|
+
addr.unit_type.should == :number
|
98
|
+
addr.unit.should == '5'
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should parse no number" do
|
102
|
+
addr = StreetAddress.parse "Westside Highway"
|
103
|
+
addr.number.should == nil
|
104
|
+
addr.name.should == 'Westside'
|
105
|
+
addr.suffix.should == :highway
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should parse directional street with suffix" do
|
109
|
+
addr = StreetAddress.parse "12 north avenue"
|
110
|
+
addr.number.should == '12'
|
111
|
+
addr.name.should == 'north'
|
112
|
+
addr.suffix.should == :avenue
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should parse directional street without suffix" do
|
116
|
+
addr = StreetAddress.parse "12 north"
|
117
|
+
addr.number.should == '12'
|
118
|
+
addr.name.should == 'north'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should parse directional street with postdir" do
|
122
|
+
addr = StreetAddress.parse "12 north w"
|
123
|
+
addr.number.should == '12'
|
124
|
+
addr.name.should == 'north'
|
125
|
+
addr.post_direction.should == :west
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should parse directional street with postdir and unit" do
|
129
|
+
addr = StreetAddress.parse "12 n sw apt. 2"
|
130
|
+
addr.number.should == '12'
|
131
|
+
addr.name.should == 'n'
|
132
|
+
addr.post_direction.should == :southwest
|
133
|
+
addr.unit_type.should == :apartment
|
134
|
+
addr.unit.should == '2'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should handle commas" do
|
138
|
+
addr = StreetAddress.parse "123 E E St NE, suite 23"
|
139
|
+
addr.number.should == '123'
|
140
|
+
addr.pre_direction.should == :east
|
141
|
+
addr.name.should == 'E'
|
142
|
+
addr.suffix.should == :street
|
143
|
+
addr.post_direction.should == :northeast
|
144
|
+
addr.unit_type.should == :suite
|
145
|
+
addr.unit.should == '23'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should support long form" do
|
149
|
+
StreetAddress.string_for(:northwest, :long).should == 'northwest'
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should support short form" do
|
153
|
+
StreetAddress.string_for(:road, :short).should == 'rd'
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should support short form when none exists" do
|
157
|
+
StreetAddress.string_for(:oaks, :short).should == StreetAddress.string_for(:oaks, :long)
|
158
|
+
end
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dburkes-people_places_things
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Burkes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.
|
17
|
+
email: dburkes@netable.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://github.com/dburkes/people_places_things
|
28
|
+
licenses:
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- --charset=UTF-8
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.3.5
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.
|
53
|
+
test_files:
|
54
|
+
- spec/person_name_spec.rb
|
55
|
+
- spec/street_address_spec.rb
|
56
|
+
- spec/ansi_counties_spec.rb
|
57
|
+
- spec/helper.rb
|