u_s_census 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/u_s_census/version.rb +1 -1
- data/lib/u_s_census.rb +24 -3
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/lib/u_s_census/version.rb
CHANGED
data/lib/u_s_census.rb
CHANGED
@@ -11,14 +11,35 @@ module USCensus
|
|
11
11
|
}
|
12
12
|
|
13
13
|
# Get 2010 Census SF1 data for the states by using
|
14
|
-
# <tt>census_summary_2010</tt> and pass it key
|
14
|
+
# <tt>census_summary_2010</tt> and pass it key, list of states (FIPS codes or
|
15
|
+
# state names) and api_variables
|
16
|
+
# (http://www.census.gov/developers/data/sf1.xml).
|
15
17
|
# This will return array of hashes.
|
16
|
-
|
18
|
+
#
|
19
|
+
# <tt>USCensus::census_summary_2010(key, ["California"], ["P0010001"])</tt>
|
20
|
+
#
|
21
|
+
def self.census_summary_2010(key, states = "*", api_variables = ["P0010001"])
|
17
22
|
states = fips_codes(states)
|
18
|
-
|
23
|
+
api_variables = api_variables.join(',')
|
24
|
+
url = HOST + "sf1?key=#{key}&get=#{api_variables},NAME&for=state:#{states}"
|
19
25
|
output = open(url)
|
20
26
|
return parse(output, key)
|
21
27
|
end
|
28
|
+
# Get ACS 2010 5 year data for for the states
|
29
|
+
# <tt>census_acs_2010</tt> and pass it key, list of states (FIPS codes or
|
30
|
+
# state names) and api_variables
|
31
|
+
# (http://www.census.gov/developers/data/2010acs5_variables.xml).
|
32
|
+
# This will return array of hashes.
|
33
|
+
#
|
34
|
+
# <tt>USCensus::census_acs_2010(key, ["California"], ["B02001_001E"])</tt>
|
35
|
+
#
|
36
|
+
def self.census_acs_2010(key, states = "*", api_variables = ["B02001_001E"])
|
37
|
+
states = fips_codes(states)
|
38
|
+
api_variables = api_variables.join(',')
|
39
|
+
url = HOST + "acs5?key=#{key}&get=B02001_001E,NAME&for=state:#{states}"
|
40
|
+
output = open(url)
|
41
|
+
return parse(output,key)
|
42
|
+
end
|
22
43
|
private
|
23
44
|
def self.fips_codes(states)
|
24
45
|
if states.is_a? Array
|