dburkes-people_places_things 1.1.0 → 1.1.2
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/.gitignore +3 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/people_places_things/ansi_counties/ansi_counties.rb +66 -0
- data/lib/people_places_things/ansi_counties/data/data.yml +3228 -0
- data/lib/people_places_things/ansi_counties/data/process_data.rb +33 -0
- data/lib/people_places_things/ansi_counties/data/raw.txt +3235 -0
- data/lib/people_places_things/person_name/person_name.rb +157 -0
- data/lib/people_places_things/phone_number/phone_number.rb +38 -0
- data/lib/people_places_things/street_address/street_address.rb +195 -0
- data/lib/people_places_things.rb +8 -0
- data/people_places_things.gemspec +61 -0
- data/spec/phone_number_spec.rb +39 -0
- metadata +23 -4
data/.gitignore
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
begin; require 'rubygems'; rescue LoadError; end
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
desc "Run all specs"
|
8
|
+
Spec::Rake::SpecTask.new('specs') do |t|
|
9
|
+
t.spec_files = FileList['spec/**/*.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir['tasks/*.rake'].each{|f| import(f) }
|
13
|
+
|
14
|
+
task :default => [:specs]
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'jeweler'
|
18
|
+
Jeweler::Tasks.new do |gemspec|
|
19
|
+
gemspec.name = "people_places_things"
|
20
|
+
gemspec.summary = "Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc."
|
21
|
+
gemspec.email = "dburkes@netable.com"
|
22
|
+
gemspec.homepage = "http://github.com/dburkes/people_places_things"
|
23
|
+
gemspec.description = "Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc."
|
24
|
+
gemspec.authors = ["Danny Burkes"]
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
28
|
+
end
|
29
|
+
|
30
|
+
namespace :doc do
|
31
|
+
desc "Generate RDoc"
|
32
|
+
Rake::RDocTask.new('people_places_things') { |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'doc'
|
34
|
+
rdoc.options << '--inline-source'
|
35
|
+
# rdoc.rdoc_files.include('README.md')
|
36
|
+
# rdoc.rdoc_files.include('lib/**/*')
|
37
|
+
# rdoc.rdoc_files.exclude('lib/ansi_counties/data/**/*')
|
38
|
+
}
|
39
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.2
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
# Provides two-way mapping between U.S. state and county names and their associated ANSI codes (formerly known as FIPS codes).
|
4
|
+
#
|
5
|
+
# == Examples
|
6
|
+
#
|
7
|
+
# To get the ANSI code for a state and county, you call ANSICounties.code_for, like so:
|
8
|
+
#
|
9
|
+
# code = ANSICounties.code_for('GA', 'FULTON')
|
10
|
+
# # => 13121
|
11
|
+
#
|
12
|
+
# You can also pass a single Hash argument:
|
13
|
+
#
|
14
|
+
# code = ANSICounties.code_for(:state => 'ga', :county => 'fulton')
|
15
|
+
# # => 13121
|
16
|
+
#
|
17
|
+
# Conversely, to get the state and county for an ANSI code, you call ANSICounties.data_for:
|
18
|
+
#
|
19
|
+
# hash = ANSICounties.data_for(13121)
|
20
|
+
# # => { :state => 'GA', :county => 'FULTON' }
|
21
|
+
#
|
22
|
+
# == Data source
|
23
|
+
#
|
24
|
+
# The data that makes up <tt>lib/ansi-counties/data/data.yml</tt> was generated from <tt>lib/ansi-counties/data/raw.txt</tt>, which was downloaded from
|
25
|
+
# the {US Census website}[http://www.census.gov/geo/www/ansi/download.html].
|
26
|
+
class ANSICounties
|
27
|
+
|
28
|
+
# Get the ANSI code for the given state and county. If _data_or_state_ is a Hash, then it must contain <em>state</em> and <em>county</em> keys, otherwise,
|
29
|
+
# it is assumbed to be a String containing the state name.
|
30
|
+
def self.code_for(data_or_state, county=nil)
|
31
|
+
if data_or_state.is_a?(Hash)
|
32
|
+
state, county = data_or_state[:state], data_or_state[:county]
|
33
|
+
else
|
34
|
+
state = data_or_state
|
35
|
+
end
|
36
|
+
|
37
|
+
forward_hash[key_for(state, county)] rescue nil
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the state and county names for a given ANSI code. Returns a Hash containing <em>state</em> and <em>county</em> keys
|
41
|
+
def self.data_for(code)
|
42
|
+
reverse_hash[code]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.normalize_county_name(name) #:nodoc:
|
46
|
+
name.upcase.gsub("ST ", "ST. ").gsub("SAINT ", "ST. ")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.key_for(state, county) #:nodoc:
|
50
|
+
"#{state.upcase}/#{normalize_county_name(county)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.forward_hash
|
56
|
+
@@forward_hash ||= File.open(File.join(File.dirname(__FILE__), 'data', 'data.yml')) {|yf| YAML::load(yf)}
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.reverse_hash
|
60
|
+
@@reverse_hash ||= forward_hash.inject({}) do |h, kv|
|
61
|
+
state_county = kv[0].split('/')
|
62
|
+
h[kv[1]] = { :state => state_county[0], :county => state_county[1]}
|
63
|
+
h
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|