Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding zipcode, updating readme

  • Loading branch information...
commit 45c063152a65d609dd4145ced066cbe6525cb4b8 1 parent fb0e524
@ajb authored
View
20 README.md
@@ -46,19 +46,20 @@ It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shape
<th>2010</th>
</tr>
<tr>
- <th>Concensus::Place</th>
- <td></td>
- <td>✓</td>
+ <th>Concensus::Congressional</th>
+ <td></td>
+ <td>✓</td>
</tr>
+
<tr>
<th>Concensus::County</th>
<td></td>
<td>✓</td>
</tr>
<tr>
- <th>Concensus::State</th>
- <td></td>
- <td>✓</td>
+ <th>Concensus::Place</th>
+ <td></td>
+ <td>✓</td>
</tr>
<tr>
<th>Concensus::School::Elementary</th>
@@ -76,6 +77,11 @@ It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shape
<td>✓</td>
</tr>
<tr>
+ <th>Concensus::State</th>
+ <td></td>
+ <td>✓</td>
+ </tr>
+ <tr>
<th>Concensus::StateLegislative::Upper</th>
<td>✓</td>
<td>✓</td>
@@ -86,7 +92,7 @@ It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shape
<td>✓</td>
</tr>
<tr>
- <th>Concensus::Congressional</th>
+ <th>Concensus::Zipcode</th>
<td></td>
<td>✓</td>
</tr>
View
11 lib/concensus.rb
@@ -1,12 +1,15 @@
-require "concensus/version"
require "concensus/configuration"
require "concensus/resource"
-require "concensus/place"
+require "concensus/version"
+
+require "concensus/congressional"
require "concensus/county"
+require "concensus/place"
+require "concensus/school"
require "concensus/state"
require "concensus/state_legislative"
-require "concensus/congressional"
-require "concensus/school"
+require "concensus/zipcode"
+
require "geo_ruby/simple_features"
require "zip/zip"
View
22 lib/concensus/zipcode.rb
@@ -0,0 +1,22 @@
+module Concensus
+ class Zipcode < Resource
+
+ def self.find(state, name = nil)
+
+ if Concensus::configuration.year == 2010
+ attribute_key = "ZCTA5CE10"
+ shp_file_path = get_and_unzip("ZCTA5/2010/tl_2010_#{state_code_to_id(state)}_zcta510.zip")
+ else
+ raise NoResourceForYear
+ end
+
+ return process_find("Zipcode", shp_file_path, attribute_key, state, name)
+
+ end
+
+ def self.find_all(state)
+ find(state)
+ end
+
+ end
+end
View
2  spec/concensus/configuration_spec.rb
@@ -1,7 +1,7 @@
require 'concensus'
describe Concensus do
-
+
describe "configuration" do
it "should have a root url" do
Concensus::configuration.root_url.should_not be_empty
View
7 spec/concensus/year_spec.rb
@@ -27,6 +27,13 @@
end.to raise_error Concensus::NoResourceForYear
end
+ it "should throw an error when a zipcode is requested for 2011" do
+ expect do
+ Concensus::configuration.year = 2011
+ Concensus::Zipcode.find("CA")
+ end.to raise_error Concensus::NoResourceForYear
+ end
+
end
end
View
19 spec/concensus/zipcode_spec.rb
@@ -0,0 +1,19 @@
+require 'concensus'
+
+describe Concensus do
+ describe "zipcodes" do
+
+ describe "2010" do
+ before { Concensus::configuration.year = 2010 }
+
+ it "should be able to find all zipcodes for a state" do
+ Concensus::Zipcode.find_all("CO").should be_instance_of(Array)
+ end
+
+ it "should be able to find one zipcode for a state" do
+ Concensus::Zipcode.find("CO", "80022").should be_instance_of(Concensus::Zipcode)
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.