census_for 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ea084ebaf7d177e9926827b5f64080943176a56
4
- data.tar.gz: fcb08da50af3e836e4413c3f24b06131272c8359
3
+ metadata.gz: 815ad82d694c0339e41b96823a50fe96766a4394
4
+ data.tar.gz: f20e6c474501790176e702b70b3e785c5a6a76ba
5
5
  SHA512:
6
- metadata.gz: b27cd6479f2ed7311f78a4e1d2f775f63855852e5577172967d7e751282b3cd6d4d27f1c3fbfe18bbb009d0960b333652da6ec4035144d229bbd35dcd586c403
7
- data.tar.gz: e6ebb1b081450ad25649923e35208d2f7dd1da2737c403e6d17106f1d82467ae74af825d47fe872b3006eab99484173b5e4f52ba8316309d652f48746b1c8191
6
+ metadata.gz: dacc3c03b89b6a9c7c8c0a601702f917df42b51b730e0c0691a50140a9cc71ffd6bea87b56ce580c04d90bfef462c3dcfd3fbd0ebdaf3ed57a66e5c54ef39ce3
7
+ data.tar.gz: b85d4870ce525cda7df93621af7de2a55392c90554886087db69bd1866f0e065beb2ad1f8900ea38c330cdd7f51e114e0f828e116b61875f6c49c987b00c7639
@@ -75,26 +75,26 @@ GEO.id,GEO.id2,GEO.display-label,rescen42010,resbase42010,respop72010,respop7201
75
75
  0500000US02070,2070,"Dillingham Census Area, Alaska",4847,4847,4869,4969,4968,4988,4988
76
76
  0500000US02090,2090,"Fairbanks North Star Borough, Alaska",97581,97581,98174,98029,100227,100807,99357
77
77
  0500000US02100,2100,"Haines Borough, Alaska",2508,2508,2504,2572,2572,2569,2566
78
- 0500000US02105,2105,"Hoonah-Angoon Census Area, Alaska",2150,2149,2149,2124,2140,2134,2082
78
+ 0500000US02105,2105,"Hoonah-angoon Census Area, Alaska",2150,2149,2149,2124,2140,2134,2082
79
79
  0500000US02110,2110,"Juneau City and Borough, Alaska",31275,31275,31386,32170,32411,32626,32406
80
80
  0500000US02122,2122,"Kenai Peninsula Borough, Alaska",55400,55400,55566,56369,56958,57067,57477
81
81
  0500000US02130,2130,"Ketchikan Gateway Borough, Alaska",13477,13477,13536,13654,13709,13695,13787
82
82
  0500000US02150,2150,"Kodiak Island Borough, Alaska",13592,13606,13637,13807,14075,14115,13986
83
83
  0500000US02164,2164,"Lake and Peninsula Borough, Alaska",1631,1635,1638,1656,1643,1662,1631
84
- 0500000US02170,2170,"Matanuska-Susitna Borough, Alaska",88995,88995,89783,91858,93798,95892,97882
84
+ 0500000US02170,2170,"Matanuska-susitna Borough, Alaska",88995,88995,89783,91858,93798,95892,97882
85
85
  0500000US02180,2180,"Nome Census Area, Alaska",9492,9492,9543,9844,9873,9884,9817
86
86
  0500000US02185,2185,"North Slope Borough, Alaska",9430,9430,9467,9534,9655,9733,9703
87
87
  0500000US02188,2188,"Northwest Arctic Borough, Alaska",7523,7523,7531,7708,7709,7697,7717
88
88
  0500000US02195,2195,"Petersburg Borough, Alaska",3815,3207,3209,3235,3241,3213,3160
89
- 0500000US02198,2198,"Prince of Wales-Hyder Census Area, Alaska",5559,6172,6214,6379,6387,6402,6396
89
+ 0500000US02198,2198,"Prince Of Wales-hyder Census Area, Alaska",5559,6172,6214,6379,6387,6402,6396
90
90
  0500000US02220,2220,"Sitka City and Borough, Alaska",8881,8881,8897,8913,9060,9014,8900
91
91
  0500000US02230,2230,"Skagway Municipality, Alaska",968,968,965,960,994,1012,1036
92
92
  0500000US02240,2240,"Southeast Fairbanks Census Area, Alaska",7029,7029,7053,7120,7149,6969,6931
93
- 0500000US02261,2261,"Valdez-Cordova Census Area, Alaska",9636,9636,9678,9752,9736,9770,9488
93
+ r500000US02261,2261,"Valdez-cordova Census Area, Alaska",9636,9636,9678,9752,9736,9770,9488
94
94
  0500000US02270,2270,"Wade Hampton Census Area, Alaska",7459,7459,7473,7662,7795,7952,8010
95
95
  0500000US02275,2275,"Wrangell City and Borough, Alaska",2369,2365,2366,2381,2398,2404,2364
96
96
  0500000US02282,2282,"Yakutat City and Borough, Alaska",662,662,661,647,651,634,635
97
- 0500000US02290,2290,"Yukon-Koyukuk Census Area, Alaska",5588,5588,5589,5733,5731,5654,5547
97
+ 0500000US02290,2290,"Yukon-koyukuk Census Area, Alaska",5588,5588,5589,5733,5731,5654,5547
98
98
  0500000US04001,4001,"Apache County, Arizona",71518,71518,71749,72354,72911,71867,71828
99
99
  0500000US04003,4003,"Cochise County, Arizona",131346,131357,131868,133058,131919,129744,127448
100
100
  0500000US04005,4005,"Coconino County, Arizona",134421,134437,134603,134159,135949,136690,137682
@@ -362,7 +362,7 @@ GEO.id,GEO.id2,GEO.display-label,rescen42010,resbase42010,respop72010,respop7201
362
362
  0500000US12081,12081,"Manatee County, Florida",322833,322833,323510,327458,334071,342417,351746
363
363
  0500000US12083,12083,"Marion County, Florida",331298,331303,331527,332507,334495,336159,339167
364
364
  0500000US12085,12085,"Martin County, Florida",146318,146850,146978,147595,148846,151478,153392
365
- 0500000US12086,12086,"Miami-Dade County, Florida",2496435,2498017,2508689,2579916,2610960,2641866,2662874
365
+ 0500000US12086,12086,"Miami-dade County, Florida",2496435,2498017,2508689,2579916,2610960,2641866,2662874
366
366
  0500000US12087,12087,"Monroe County, Florida",73090,73090,73226,74151,74991,76536,77136
367
367
  0500000US12089,12089,"Nassau County, Florida",73314,73314,73543,74159,74640,75628,76619
368
368
  0500000US12091,12091,"Okaloosa County, Florida",180822,180822,180751,183314,190437,193906,196512
@@ -1355,7 +1355,7 @@ GEO.id,GEO.id2,GEO.display-label,rescen42010,resbase42010,respop72010,respop7201
1355
1355
  0500000US27071,27071,"Koochiching County, Minnesota",13311,13311,13301,13236,13180,13117,12856
1356
1356
  0500000US27073,27073,"Lac qui Parle County, Minnesota",7259,7259,7233,7231,7116,7010,6891
1357
1357
  0500000US27075,27075,"Lake County, Minnesota",10866,10866,10863,10805,10830,10778,10680
1358
- 0500000US27077,27077,"Lake of the Woods County, Minnesota",4045,4045,4041,4023,3968,3931,3918
1358
+ 0500000US27077,27077,"Lake Of The Woods County, Minnesota",4045,4045,4041,4023,3968,3931,3918
1359
1359
  0500000US27079,27079,"Le Sueur County, Minnesota",27703,27703,27690,27802,27647,27678,27770
1360
1360
  0500000US27081,27081,"Lincoln County, Minnesota",5896,5896,5877,5846,5800,5792,5788
1361
1361
  0500000US27083,27083,"Lyon County, Minnesota",25857,25857,25856,25808,25618,25674,25665
@@ -2870,7 +2870,7 @@ GEO.id,GEO.id2,GEO.display-label,rescen42010,resbase42010,respop72010,respop7201
2870
2870
  0500000US51087,51087,"Henrico County, Virginia",306935,306906,307542,310550,315431,318943,321924
2871
2871
  0500000US51089,51089,"Henry County, Virginia",54151,54143,54094,53274,52824,52527,52081
2872
2872
  0500000US51091,51091,"Highland County, Virginia",2321,2319,2294,2279,2249,2219,2248
2873
- 0500000US51093,51093,"Isle of Wight County, Virginia",35270,35270,35288,35274,35380,35643,36007
2873
+ 0500000US51093,51093,"Isle Of Wight County, Virginia",35270,35270,35288,35274,35380,35643,36007
2874
2874
  0500000US51095,51095,"James City County, Virginia",67009,67401,67751,68329,69532,70964,72583
2875
2875
  0500000US51097,51097,"King and Queen County, Virginia",6945,6945,6970,7032,7068,7118,7175
2876
2876
  0500000US51099,51099,"King George County, Virginia",23584,23584,23676,24279,24608,24950,25371
data/lib/census_for.rb CHANGED
@@ -2,7 +2,7 @@ require 'smarter_csv'
2
2
 
3
3
  class CensusFor
4
4
 
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.5"
6
6
 
7
7
  STATES =
8
8
  {
@@ -49,37 +49,63 @@ class CensusFor
49
49
  end
50
50
 
51
51
  class County
52
+
52
53
  def self.population(request)
53
- parsed_request = parse_county_state(request)
54
- return population_lookup(parsed_request)
54
+ self.new(request).population
55
55
  end
56
56
 
57
- def self.parse_county_state(county_state)
58
- transit = county_state.downcase.split(/[\s,]+/) - ["county"] - ["parish"] - ["borough"] - ["municipio"] - ["municipality"]
59
- if transit.size >= 3
60
- city_state_key_array = []
61
- 1.upto((transit.size - 1)) do |x|
62
- y = transit.size
63
- first = transit.take(x).join(' ')
64
- second = transit.last(y-x).join(' ')
65
- city_state_key_array << [first, second].flatten
66
- end
67
- else
68
- city_state_key_array = [transit]
57
+ def self.parse_county_state(request)
58
+ self.new(request).parse_county_state
59
+ end
60
+
61
+ def initialize(request)
62
+ @request = request
63
+ @request_array = request_to_array_minus_countystring
64
+ match_state_and_county
65
+ end
66
+
67
+
68
+ def match_state_and_county
69
+ if @state = Abbrev.converter(@request_array.last)
70
+ @county = @request_array[0...-1].join(' ')
71
+ elsif @state = Abbrev.converter(@request_array.last(2).join(' '))
72
+ @county = @request_array[0...-2].join(' ')
73
+ elsif @state = Abbrev.converter(@request_array.last(3).join(' '))
74
+ @county = @request_array[0...-3].join(' ')
69
75
  end
70
- city_state_key_array.each do |cs|
71
- county_name = cs.first
72
- state_name = cs.last
73
- state = Abbrev.converter(state_name)
74
- result = CensusData.data.find { |x| x[:"geo.display_label"] ==
75
- "#{county_name.split.map(&:capitalize).join(' ')} County, #{state}" || x[:"geo.display_label"] == "#{county_name.split.map(&:capitalize).join(' ')} Parish, Louisiana" || x[:"geo.display_label"] == "#{county_name.split.map(&:capitalize).join(' ')} Municipio, Puerto Rico" }
76
- if result
77
- return result[:"geo.display_label"]
78
- end
76
+ @county = titleize(@county)
77
+ end
78
+
79
+ def population
80
+ parsed_request = parse_county_state
81
+ return County.population_lookup(parsed_request)
82
+ end
83
+
84
+ def parse_county_state
85
+ result = CensusData.data.find do |x|
86
+ x[:"geo.display_label"] == "#{@county} County, #{@state}" ||
87
+ x[:"geo.display_label"] == "#{@county} Parish, #{@state}" ||
88
+ x[:"geo.display_label"] == "#{@county} Municipio, #{@state}" ||
89
+ x[:"geo.display_label"] == "#{@county} Municipality, #{@state}" ||
90
+ x[:"geo.display_label"] == "#{@county} Borough, #{@state}" ||
91
+ x[:"geo.display_label"] == "#{@county} Census Area, #{@state}" ||
92
+ x[:"geo.display_label"] == "#{@county} City County, #{@state}" ||
93
+ x[:"geo.display_label"] == "#{@county} City and Borough, #{@state}"
94
+ end
95
+ if result
96
+ return result[:"geo.display_label"]
79
97
  end
80
98
  return "not found"
81
99
  end
82
100
 
101
+ def titleize(string)
102
+ string.split.map(&:capitalize).join(' ')
103
+ end
104
+
105
+ def request_to_array_minus_countystring
106
+ @request.downcase.split(/[\s,]+/) - ["county"] - ["parish"] - ["borough"] - ["municipio"] - ["municipality"] - ["census"] - ["area"] - ["city"] - ["and"]
107
+ end
108
+
83
109
  def self.population_lookup(parsed_county_state)
84
110
  if parsed_county_state == "not found"
85
111
  return "not found"
@@ -87,17 +113,6 @@ class CensusFor
87
113
  return CensusData.data.find { |x| x[:"geo.display_label"] == parsed_county_state }[:respop72014]
88
114
  end
89
115
  end
90
-
91
- def self.coeff(county_state)
92
- coefficient = (population(county_state) * 1000 / highest_county_pop).to_f
93
- coefficient < 1 ? 1 : coefficient
94
- end
95
-
96
- def self.highest_county_pop
97
- most_populous_county = CensusData.data.max_by { |x| x[:respop72014] }
98
- most_populous_county[:respop72014]
99
- #for 2014, this is Los Angeles County, CA: pop 10,116,705
100
- end
101
116
  end
102
117
 
103
118
  class State
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: census_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smarter_csv
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Gem returns population data for US States, Counties, and a linear ranking/weight
84
- coefficient of US counties by population.
83
+ description: Gem returns population data for US States, Counties, including Puerto
84
+ Rico, US territories.
85
85
  email:
86
86
  - evankoch@gmail.com
87
87
  executables: []