concensus 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Concensus
2
2
 
3
- Concensus is a gem for reading the United States Census Bureau's TIGER/Line Shapefiles.
3
+ Concensus is a gem for reading the United States Census Bureau's [TIGER/Line Shapefiles](http://www.census.gov/geo/www/tiger/).
4
4
 
5
5
  It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shapefiles, which leaves you with access to all of the methods in the [georuby API](http://www.ruby-doc.org/gems/docs/g/georuby-1.9.7/GeoRuby/SimpleFeatures/MultiPolygon.html).
6
6
 
@@ -12,10 +12,18 @@ It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shape
12
12
  ## Use
13
13
 
14
14
  Concensus::Place.find("CA", "Berkeley")
15
- => #<Concensus::Resource>
15
+ => #<Concensus::Place>
16
16
 
17
17
  Concensus::Place.find_all("CA")
18
- => [#<Concensus::Resource>, #<Concensus::Resource>, etc...]
18
+ => [#<Concensus::Place>, #<Concensus::Place>, etc...]
19
+
20
+ Concensus::configuration.year = 2011
21
+ => all subsequent requests will be for 2011
22
+
23
+ Concensus::Place.find("NY", "New York")
24
+ => 2011 Boundaries for New York City
25
+
26
+ Concensus::configuration.year = 2010
19
27
 
20
28
  california = Concensus::State.find("CA")
21
29
 
@@ -27,10 +35,73 @@ It uses the [georuby](http://rubygems.org/gems/georuby) gem to convert the shape
27
35
 
28
36
  california.geometry.to_array[0]
29
37
  => [[-119.000932, 33.535895], [-119.000932, 33.535823], ... ]
38
+
39
+
40
+ ### List of Resources
41
+
42
+ <table style="text-align: left;" cellpadding="5" border="1">
43
+ <tr>
44
+ <th></th>
45
+ <th>2011</th>
46
+ <th>2010</th>
47
+ </tr>
48
+ <tr>
49
+ <th>Concensus::Congressional</th>
50
+ <td></td>
51
+ <td>✓</td>
52
+ </tr>
53
+
54
+ <tr>
55
+ <th>Concensus::County</th>
56
+ <td></td>
57
+ <td>✓</td>
58
+ </tr>
59
+ <tr>
60
+ <th>Concensus::Place</th>
61
+ <td>✓</td>
62
+ <td>✓</td>
63
+ </tr>
64
+ <tr>
65
+ <th>Concensus::School::Elementary</th>
66
+ <td>✓</td>
67
+ <td>✓</td>
68
+ </tr>
69
+ <tr>
70
+ <th>Concensus::School::Secondary</th>
71
+ <td>✓</td>
72
+ <td>✓</td>
73
+ </tr>
74
+ <tr>
75
+ <th>Concensus::School::Unified</th>
76
+ <td>✓</td>
77
+ <td>✓</td>
78
+ </tr>
79
+ <tr>
80
+ <th>Concensus::State</th>
81
+ <td></td>
82
+ <td>✓</td>
83
+ </tr>
84
+ <tr>
85
+ <th>Concensus::StateLegislative::Upper</th>
86
+ <td>✓</td>
87
+ <td>✓</td>
88
+ </tr>
89
+ <tr>
90
+ <th>Concensus::StateLegislative::Lower</th>
91
+ <td>✓</td>
92
+ <td>✓</td>
93
+ </tr>
94
+ <tr>
95
+ <th>Concensus::Zipcode</th>
96
+ <td></td>
97
+ <td>✓</td>
98
+ </tr>
99
+ </table>
100
+
30
101
 
31
102
 
32
103
  ### Full Documentation
33
- [http://www.googl.com]()
104
+ [http://rubydoc.info/github/adamjacobbecker/concensus/](http://rubydoc.info/github/adamjacobbecker/concensus/)
34
105
 
35
106
  ### Notes
36
107
 
@@ -40,8 +111,7 @@ If you're using Rails, you'll probably want to create an initializer with `Conce
40
111
 
41
112
  #### Todo
42
113
 
43
- - Add support for switching Census year (already started, not fully implemented yet.)
44
114
  - Add more geographic areas, we only have a small bit of [what's available](http://www.census.gov/geo/www/tiger/tgrshp2010/availability.html).
45
115
  - Add support for storing downloaded and uncompressed .zips on S3. (Heroku has no persistent writable file storage.)
46
116
 
47
- **Support development by sending links to sick house music mixes:** [@AdamJacobBecker](http://www.twitter.com/AdamJacobBecker)
117
+ **Support development by sending links to siiick house mixes:** [@AdamJacobBecker](http://www.twitter.com/AdamJacobBecker)
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_development_dependency x
20
20
  end
21
21
 
22
- %w{rspec activesupport rubyzip georuby dbf}.each do |x|
22
+ %w{activesupport rubyzip georuby dbf}.each do |x|
23
23
  gem.add_dependency x
24
24
  end
25
25
  end
@@ -1,16 +1,25 @@
1
- require "concensus/version"
2
1
  require "concensus/configuration"
3
2
  require "concensus/resource"
4
- require "concensus/place"
3
+ require "concensus/version"
4
+
5
+ require "concensus/congressional"
5
6
  require "concensus/county"
7
+ require "concensus/place"
8
+ require "concensus/school"
6
9
  require "concensus/state"
7
10
  require "concensus/state_legislative"
8
- require "concensus/congressional"
9
- require "concensus/school"
11
+ require "concensus/zipcode"
12
+
10
13
  require "geo_ruby/simple_features"
11
- require "active_support"
12
14
  require "zip/zip"
13
15
 
14
16
  module Concensus
17
+ class ConcensusError < StandardError; end
18
+
19
+ class ShapeNotFound < ConcensusError; end
20
+
21
+ class YearNotSupported < ConcensusError; end
22
+
23
+ class NoResourceForYear < ConcensusError; end
15
24
  end
16
25
 
@@ -1,7 +1,6 @@
1
1
  module Concensus
2
2
  class Configuration
3
- attr_accessor :year, :census_state_ids
4
- attr_reader :tmp_dir, :default_tmp_dir
3
+ attr_reader :tmp_dir, :default_tmp_dir, :year, :census_state_ids
5
4
 
6
5
  # Temporary directory for storing .zip files and their contents.
7
6
  # It's best if this directory persists as a "cache" of sorts, so
@@ -14,10 +13,22 @@ module Concensus
14
13
  FileUtils.mkdir_p(@tmp_dir)
15
14
  end
16
15
 
16
+ def year=(x)
17
+ if [2010, 2011].include?(x)
18
+ @year = x
19
+ else
20
+ raise YearNotSupported
21
+ end
22
+ end
23
+
17
24
  # This will become useful once we can switch years...
18
25
  def root_url
19
26
  "http://www2.census.gov/geo/tiger/TIGER#{@year}/"
20
27
  end
28
+
29
+ def short_year
30
+ @year.to_s[-2, 2]
31
+ end
21
32
 
22
33
  def initialize
23
34
  @year = 2010
@@ -1,13 +1,16 @@
1
1
  module Concensus
2
2
  class Congressional < Resource
3
3
 
4
- # @return [Concensus::Resource] matched congressional district
5
4
  def self.find(state, name = nil)
6
- shp_file_path = get_and_unzip("CD/111/tl_2010_#{state_code_to_id(state)}_cd111.zip")
7
- return process_find(shp_file_path, "NAMELSAD10", state, name)
5
+ if Concensus::configuration.year == 2010
6
+ attribute_key = "NAMELSAD10"
7
+ shp_file_path = get_and_unzip("CD/111/tl_2010_#{state_code_to_id(state)}_cd111.zip")
8
+ return process_find("Congressional", shp_file_path, attribute_key, state, name)
9
+ else
10
+ raise NoResourceForYear
11
+ end
8
12
  end
9
-
10
- # @return [Array] array of all congressional districts for a state
13
+
11
14
  def self.find_all(state)
12
15
  find(state)
13
16
  end
@@ -1,13 +1,16 @@
1
1
  module Concensus
2
2
  class County < Resource
3
-
4
- # @return [Concensus::Resource] matched county
3
+
5
4
  def self.find(state, name = nil)
6
- shp_file_path = get_and_unzip("COUNTY/2010/tl_2010_#{state_code_to_id(state)}_county10.zip")
7
- return process_find(shp_file_path, "NAME10", state, name)
5
+ if Concensus::configuration.year == 2010
6
+ attribute_key = "NAME10"
7
+ shp_file_path = get_and_unzip("COUNTY/2010/tl_2010_#{state_code_to_id(state)}_county10.zip")
8
+ return process_find("County", shp_file_path, attribute_key, state, name)
9
+ else
10
+ raise NoResourceForYear
11
+ end
8
12
  end
9
-
10
- # @return [Array] all counties for a state
13
+
11
14
  def self.find_all(state)
12
15
  find(state)
13
16
  end
@@ -1,13 +1,20 @@
1
1
  module Concensus
2
2
  class Place < Resource
3
-
4
- # @return [Concensus::Resource] matched place
3
+
5
4
  def self.find(state, name = nil)
6
- shp_file_path = get_and_unzip("PLACE/2010/tl_2010_#{state_code_to_id(state)}_place10.zip")
7
- return process_find(shp_file_path, "NAME10", state, name)
5
+
6
+ if Concensus::configuration.year == 2011
7
+ attribute_key = "NAMELSAD"
8
+ shp_file_path = get_and_unzip("PLACE/tl_2011_#{state_code_to_id(state)}_place.zip")
9
+ elsif Concensus::configuration.year == 2010
10
+ attribute_key = "NAME10"
11
+ shp_file_path = get_and_unzip("PLACE/2010/tl_2010_#{state_code_to_id(state)}_place10.zip")
12
+ end
13
+
14
+ return process_find("Place", shp_file_path, attribute_key, state, name)
15
+
8
16
  end
9
17
 
10
- # @return [Array] all places for a state
11
18
  def self.find_all(state)
12
19
  find(state)
13
20
  end
@@ -2,6 +2,8 @@ require "zip/zip"
2
2
  require "geo_ruby"
3
3
  require "geo_ruby/shp"
4
4
  require "open-uri"
5
+ require "active_support"
6
+ require 'active_support/inflector'
5
7
 
6
8
  module Concensus
7
9
  class Resource
@@ -60,7 +62,7 @@ module Concensus
60
62
  #
61
63
  # @return [Array] returns array if we're looking for mulitple regions
62
64
  # @return [Resource] returns resource if we're looking for a specific region
63
- def self.process_find(shp_file_path, identifier, state, name = nil)
65
+ def self.process_find(class_name, shp_file_path, identifier, state, name = nil)
64
66
 
65
67
  # Prevent annoying georuby error messages
66
68
  previous_stderr, $stderr = $stderr, StringIO.new
@@ -68,13 +70,13 @@ module Concensus
68
70
  if name
69
71
  GeoRuby::Shp4r::ShpFile.open(shp_file_path) do |shp|
70
72
  matched_shape = shp.find {|x| x.data[identifier].match(name) }
71
- raise StandardError if !matched_shape
72
- return Resource.new(matched_shape.data[identifier], matched_shape.geometry, state)
73
+ raise ShapeNotFound if !matched_shape
74
+ return class_name.split('::').reduce(Concensus){|cls, c| cls.const_get(c) }.new(matched_shape.data[identifier], matched_shape.geometry, state)
73
75
  end
74
76
  else
75
77
  places = []
76
78
  GeoRuby::Shp4r::ShpFile.open(shp_file_path).each do |shp|
77
- places << Resource.new(shp.data[identifier], shp.geometry, state)
79
+ places << class_name.split('::').reduce(Concensus){|cls, c| cls.const_get(c) }.new(shp.data[identifier], shp.geometry, state)
78
80
  end
79
81
  return places
80
82
  end
@@ -2,39 +2,54 @@ module Concensus
2
2
  class School < Resource
3
3
 
4
4
  class Elementary < School
5
- # @return [Concensus::Resource] matched elementary school district
6
5
  def self.find(state, name = nil)
7
- shp_file_path = get_and_unzip("ELSD/2010/tl_2010_#{state_code_to_id(state)}_elsd10.zip")
8
- return process_find(shp_file_path, "NAME10", state, name)
6
+ if Concensus::configuration.year == 2010
7
+ attribute_key = "NAME10"
8
+ shp_file_path = get_and_unzip("ELSD/2010/tl_2010_#{state_code_to_id(state)}_elsd10.zip")
9
+ elsif Concensus::configuration.year == 2011
10
+ attribute_key = "name"
11
+ shp_file_path = get_and_unzip("ELSD/tl_2011_#{state_code_to_id(state)}_elsd.zip")
12
+ end
13
+
14
+ return process_find("School::Elementary", shp_file_path, attribute_key, state, name)
9
15
  end
10
16
 
11
- # @return [Array] all elementary school districts for a state
12
17
  def self.find_all(state)
13
18
  find(state)
14
19
  end
15
20
  end
16
21
 
17
22
  class Secondary < School
18
- # @return [Concensus::Resource] matched secondary school district
19
23
  def self.find(state, name = nil)
20
- shp_file_path = get_and_unzip("SCSD/2010/tl_2010_#{state_code_to_id(state)}_scsd10.zip")
21
- return process_find(shp_file_path, "NAME10", state, name)
24
+ if Concensus::configuration.year == 2010
25
+ attribute_key = "NAME10"
26
+ shp_file_path = get_and_unzip("SCSD/2010/tl_2010_#{state_code_to_id(state)}_scsd10.zip")
27
+ elsif Concensus::configuration.year == 2011
28
+ attribute_key = "name"
29
+ shp_file_path = get_and_unzip("SCSD/tl_2011_#{state_code_to_id(state)}_scsd.zip")
30
+ end
31
+
32
+ return process_find("School::Secondary", shp_file_path, attribute_key, state, name)
22
33
  end
23
-
24
- # @return [Array] all secondary school districts for a state
34
+
25
35
  def self.find_all(state)
26
36
  find(state)
27
37
  end
28
38
  end
29
39
 
30
40
  class Unified < School
31
- # @return [Concensus::Resource] matched unified school district
32
41
  def self.find(state, name = nil)
33
- shp_file_path = get_and_unzip("UNSD/2010/tl_2010_#{state_code_to_id(state)}_unsd10.zip")
34
- return process_find(shp_file_path, "NAME10", state, name)
42
+ if Concensus::configuration.year == 2010
43
+ attribute_key = "NAME10"
44
+ shp_file_path = get_and_unzip("UNSD/2010/tl_2010_#{state_code_to_id(state)}_unsd10.zip")
45
+ elsif Concensus::configuration.year == 2011
46
+ attribute_key = "name"
47
+ shp_file_path = get_and_unzip("UNSD/tl_2011_#{state_code_to_id(state)}_unsd.zip")
48
+ end
49
+
50
+ return process_find("School::Unified", shp_file_path, attribute_key, state, name)
35
51
  end
36
52
 
37
- # @return [Array] all unified school districts for a state
38
53
  def self.find_all(state)
39
54
  find(state)
40
55
  end
@@ -1,10 +1,16 @@
1
1
  module Concensus
2
2
  class State < Resource
3
-
3
+
4
4
  # @return [Concensus::Resource] matched state
5
5
  def self.find(state)
6
- shp_file_path = get_and_unzip("STATE/2010/tl_2010_#{state_code_to_id(state)}_state10.zip")
7
- return process_find(shp_file_path, "NAME10", state)[0]
6
+
7
+ if Concensus::configuration.year == 2010
8
+ shp_file_path = get_and_unzip("STATE/2010/tl_2010_#{state_code_to_id(state)}_state10.zip")
9
+ return process_find("State", shp_file_path, "NAME10", state)[0]
10
+ else
11
+ raise NoResourceForYear
12
+ end
13
+
8
14
  end
9
15
 
10
16
  # @return [Array] all states
@@ -2,26 +2,36 @@ module Concensus
2
2
  class StateLegislative < Resource
3
3
 
4
4
  class Upper < StateLegislative
5
- # @return [Concensus::Resource] matched state upper legislative district
6
5
  def self.find(state, name = nil)
7
- shp_file_path = get_and_unzip("SLDU/2010/tl_2010_#{state_code_to_id(state)}_sldu10.zip")
8
- return process_find(shp_file_path, "NAMELSAD10", state, name)
6
+ if Concensus::configuration.year == 2011
7
+ attribute_key = "NAMELSAD"
8
+ shp_file_path = get_and_unzip("SLDU/tl_2011_#{state_code_to_id(state)}_sldu.zip")
9
+ elsif Concensus::configuration.year == 2010
10
+ attribute_key = "NAMELSAD10"
11
+ shp_file_path = get_and_unzip("SLDU/2010/tl_2010_#{state_code_to_id(state)}_sldu10.zip")
12
+ end
13
+
14
+ return process_find("StateLegislative::Upper", shp_file_path, attribute_key, state, name)
9
15
  end
10
16
 
11
- # @return [Array] all state's upper legislative districts
12
17
  def self.find_all(state)
13
18
  find(state)
14
- end
19
+ end
15
20
  end
16
21
 
17
22
  class Lower < StateLegislative
18
- # @return [Concensus::Resource] matched state lower legislative district
19
23
  def self.find(state, name = nil)
20
- shp_file_path = get_and_unzip("SLDL/2010/tl_2010_#{state_code_to_id(state)}_sldl10.zip")
21
- return process_find(shp_file_path, "NAMELSAD10", state, name)
24
+ if Concensus::configuration.year == 2011
25
+ attribute_key = "NAMELSAD"
26
+ shp_file_path = get_and_unzip("SLDL/tl_2011_#{state_code_to_id(state)}_sldl.zip")
27
+ elsif Concensus::configuration.year == 2010
28
+ attribute_key = "NAMELSAD10"
29
+ shp_file_path = get_and_unzip("SLDL/2010/tl_2010_#{state_code_to_id(state)}_sldl10.zip")
30
+ end
31
+
32
+ return process_find("StateLegislative::Lower", shp_file_path, attribute_key, state, name)
22
33
  end
23
34
 
24
- # @return [Array] all state's lower legislative district
25
35
  def self.find_all(state)
26
36
  find(state)
27
37
  end
@@ -1,3 +1,3 @@
1
1
  module Concensus
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,22 @@
1
+ module Concensus
2
+ class Zipcode < Resource
3
+
4
+ def self.find(state, name = nil)
5
+
6
+ if Concensus::configuration.year == 2010
7
+ attribute_key = "ZCTA5CE10"
8
+ shp_file_path = get_and_unzip("ZCTA5/2010/tl_2010_#{state_code_to_id(state)}_zcta510.zip")
9
+ else
10
+ raise NoResourceForYear
11
+ end
12
+
13
+ return process_find("Zipcode", shp_file_path, attribute_key, state, name)
14
+
15
+ end
16
+
17
+ def self.find_all(state)
18
+ find(state)
19
+ end
20
+
21
+ end
22
+ end
@@ -1,12 +1,16 @@
1
1
  require 'concensus'
2
2
 
3
3
  describe Concensus do
4
-
4
+
5
5
  describe "configuration" do
6
6
  it "should have a root url" do
7
7
  Concensus::configuration.root_url.should_not be_empty
8
8
  end
9
9
 
10
+ it "should have a short year" do
11
+ Concensus::configuration.short_year.should == "10"
12
+ end
13
+
10
14
  describe "should be able to manually set the tmp file" do
11
15
  before { Concensus::configuration.tmp_dir = "tmp/concensustest/" }
12
16
  after do
@@ -24,14 +28,24 @@ describe Concensus do
24
28
  end
25
29
 
26
30
  describe "should be able to manually set the year" do
27
- before { Concensus::configuration.year = 2000 }
31
+ before { Concensus::configuration.year = 2011 }
28
32
  after { Concensus::configuration.year = 2010 }
29
33
 
30
34
  it "should be updated" do
31
- Concensus::configuration.year.should == 2000
32
- Concensus::configuration.root_url.should match(/2000/)
35
+ Concensus::configuration.year.should == 2011
36
+ Concensus::configuration.root_url.should match(/2011/)
33
37
  end
34
38
  end
39
+
40
+ it "should raise error for not supported years" do
41
+ expect do
42
+ Concensus::configuration.year = 2000
43
+ end.to raise_error(Concensus::YearNotSupported)
44
+ end
45
+
46
+ it "shouldn't have changed the year" do
47
+ Concensus::configuration.year.should == 2010
48
+ end
35
49
  end
36
50
 
37
51
  end
@@ -4,7 +4,7 @@ describe Concensus do
4
4
  describe "congressional districts" do
5
5
 
6
6
  it "should be able to find a congressional district district for a state" do
7
- Concensus::Congressional.find("CA", "13").should be_instance_of(Concensus::Resource)
7
+ Concensus::Congressional.find("CA", "13").should be_instance_of(Concensus::Congressional)
8
8
  end
9
9
 
10
10
  it "should be able to find all upper legislative districts for a state" do
@@ -8,7 +8,7 @@ describe Concensus do
8
8
  end
9
9
 
10
10
  it "should be able to find one county for a state" do
11
- Concensus::County.find("CA", "Alameda").should be_instance_of(Concensus::Resource)
11
+ Concensus::County.find("CA", "Alameda").should be_instance_of(Concensus::County)
12
12
  end
13
13
 
14
14
  end
@@ -3,12 +3,28 @@ require 'concensus'
3
3
  describe Concensus do
4
4
  describe "places" do
5
5
 
6
- it "should be able to find all places for a state" do
7
- Concensus::Place.find_all("CA").should be_instance_of(Array)
6
+ describe "2010" do
7
+ before { Concensus::configuration.year = 2010 }
8
+
9
+ it "should be able to find all places for a state" do
10
+ Concensus::Place.find_all("CA").should be_instance_of(Array)
11
+ end
12
+
13
+ it "should be able to find one places for a state" do
14
+ Concensus::Place.find("CA", "Berkeley").should be_instance_of(Concensus::Place)
15
+ end
8
16
  end
17
+
18
+ describe "2011" do
19
+ before { Concensus::configuration.year = 2011 }
20
+
21
+ it "should be able to find all places for a state" do
22
+ Concensus::Place.find_all("CA").should be_instance_of(Array)
23
+ end
9
24
 
10
- it "should be able to find one places for a state" do
11
- Concensus::Place.find("CA", "Berkeley").should be_instance_of(Concensus::Resource)
25
+ it "should be able to find one places for a state" do
26
+ Concensus::Place.find("CA", "Berkeley").should be_instance_of(Concensus::Place)
27
+ end
12
28
  end
13
29
 
14
30
  end
@@ -3,33 +3,71 @@ require 'concensus'
3
3
  describe Concensus do
4
4
  describe "school districts" do
5
5
 
6
- describe "elementary" do
7
- it "should be able to find an elementary school district for a state" do
8
- Concensus::School::Elementary.find("AZ", "San Fernando").should be_instance_of(Concensus::Resource)
9
- end
6
+ describe "2011" do
7
+ before { Concensus::configuration.year = 2011 }
8
+
9
+ describe "elementary" do
10
+ it "should be able to find an elementary school district for a state" do
11
+ Concensus::School::Elementary.find("AZ", "San Fernando").should be_instance_of(Concensus::School::Elementary)
12
+ end
10
13
 
11
- it "should be able to find all elementary school districts for a state" do
12
- Concensus::School::Elementary.find_all("AZ").should be_instance_of(Array)
14
+ it "should be able to find all elementary school districts for a state" do
15
+ Concensus::School::Elementary.find_all("AZ").should be_instance_of(Array)
16
+ end
13
17
  end
14
- end
15
-
16
- describe "elementary" do
17
- it "should be able to find a secondary school district for a state" do
18
- Concensus::School::Secondary.find("AZ", "Tempe Union").should be_instance_of(Concensus::Resource)
18
+
19
+ describe "secondary" do
20
+ it "should be able to find a secondary school district for a state" do
21
+ Concensus::School::Secondary.find("AZ", "Tempe Union").should be_instance_of(Concensus::School::Secondary)
22
+ end
23
+
24
+ it "should be able to find all secondary school districts for a state" do
25
+ Concensus::School::Secondary.find_all("AZ").should be_instance_of(Array)
26
+ end
19
27
  end
20
28
 
21
- it "should be able to find all secondary school districts for a state" do
22
- Concensus::School::Secondary.find_all("AZ").should be_instance_of(Array)
29
+ describe "unified" do
30
+ it "should be able to find a unified school district for a state" do
31
+ Concensus::School::Unified.find("AZ", "Chandler").should be_instance_of(Concensus::School::Unified)
32
+ end
33
+
34
+ it "should be able to find all unified school districts for a state" do
35
+ Concensus::School::Unified.find_all("AZ").should be_instance_of(Array)
36
+ end
23
37
  end
24
38
  end
25
39
 
26
- describe "unified" do
27
- it "should be able to find a unified school district for a state" do
28
- Concensus::School::Unified.find("AZ", "Chandler").should be_instance_of(Concensus::Resource)
40
+ describe "2010" do
41
+ before { Concensus::configuration.year = 2010 }
42
+
43
+ describe "elementary" do
44
+ it "should be able to find an elementary school district for a state" do
45
+ Concensus::School::Elementary.find("AZ", "San Fernando").should be_instance_of(Concensus::School::Elementary)
46
+ end
47
+
48
+ it "should be able to find all elementary school districts for a state" do
49
+ Concensus::School::Elementary.find_all("AZ").should be_instance_of(Array)
50
+ end
29
51
  end
30
52
 
31
- it "should be able to find all unified school districts for a state" do
32
- Concensus::School::Unified.find_all("AZ").should be_instance_of(Array)
53
+ describe "secondary" do
54
+ it "should be able to find a secondary school district for a state" do
55
+ Concensus::School::Secondary.find("AZ", "Tempe Union").should be_instance_of(Concensus::School::Secondary)
56
+ end
57
+
58
+ it "should be able to find all secondary school districts for a state" do
59
+ Concensus::School::Secondary.find_all("AZ").should be_instance_of(Array)
60
+ end
61
+ end
62
+
63
+ describe "unified" do
64
+ it "should be able to find a unified school district for a state" do
65
+ Concensus::School::Unified.find("AZ", "Chandler").should be_instance_of(Concensus::School::Unified)
66
+ end
67
+
68
+ it "should be able to find all unified school districts for a state" do
69
+ Concensus::School::Unified.find_all("AZ").should be_instance_of(Array)
70
+ end
33
71
  end
34
72
  end
35
73
 
@@ -3,24 +3,56 @@ require 'concensus'
3
3
  describe Concensus do
4
4
  describe "state legislative districts" do
5
5
 
6
- describe "upper" do
7
- it "should be able to find an upper legislative district for a state" do
8
- Concensus::StateLegislative::Upper.find("CA", "13").should be_instance_of(Concensus::Resource)
6
+ describe "2011" do
7
+
8
+ before { Concensus::configuration.year = 2011 }
9
+
10
+ describe "upper" do
11
+ it "should be able to find an upper legislative district for a state" do
12
+ Concensus::StateLegislative::Upper.find("CA", "13").should be_instance_of(Concensus::StateLegislative::Upper)
13
+ end
14
+
15
+ it "should be able to find all upper legislative districts for a state" do
16
+ Concensus::StateLegislative::Upper.find_all("CA").should be_instance_of(Array)
17
+ end
9
18
  end
19
+
20
+ describe "lower" do
21
+ it "should be able to find a lower legislative district for a state" do
22
+ Concensus::StateLegislative::Lower.find("CA", "13").should be_instance_of(Concensus::StateLegislative::Lower)
23
+ end
10
24
 
11
- it "should be able to find all upper legislative districts for a state" do
12
- Concensus::StateLegislative::Upper.find_all("CA").should be_instance_of(Array)
25
+ it "should be able to find all lower legislative districts for a state" do
26
+ Concensus::StateLegislative::Lower.find_all("CA").should be_instance_of(Array)
27
+ end
13
28
  end
14
29
  end
15
30
 
16
- describe "lower" do
17
- it "should be able to find a lower legislative district for a state" do
18
- Concensus::StateLegislative::Lower.find("CA", "13").should be_instance_of(Concensus::Resource)
31
+ describe "2010" do
32
+
33
+ before { Concensus::configuration.year = 2010 }
34
+
35
+ describe "upper" do
36
+ it "should be able to find an upper legislative district for a state" do
37
+ Concensus::StateLegislative::Upper.find("CA", "13").should be_instance_of(Concensus::StateLegislative::Upper)
38
+ end
39
+
40
+ it "should be able to find all upper legislative districts for a state" do
41
+ Concensus::StateLegislative::Upper.find_all("CA").should be_instance_of(Array)
42
+ end
19
43
  end
44
+
45
+ describe "lower" do
46
+ it "should be able to find a lower legislative district for a state" do
47
+ Concensus::StateLegislative::Lower.find("CA", "13").should be_instance_of(Concensus::StateLegislative::Lower)
48
+ end
20
49
 
21
- it "should be able to find all lower legislative districts for a state" do
22
- Concensus::StateLegislative::Lower.find_all("CA").should be_instance_of(Array)
50
+ it "should be able to find all lower legislative districts for a state" do
51
+ Concensus::StateLegislative::Lower.find_all("CA").should be_instance_of(Array)
52
+ end
23
53
  end
24
54
  end
55
+
56
+
25
57
  end
26
58
  end
@@ -4,7 +4,7 @@ describe Concensus do
4
4
  describe "states" do
5
5
 
6
6
  it "should be able to find a state" do
7
- Concensus::State.find("CA").should be_instance_of(Concensus::Resource)
7
+ Concensus::State.find("CA").should be_instance_of(Concensus::State)
8
8
  end
9
9
 
10
10
  end
@@ -0,0 +1,39 @@
1
+ require 'concensus'
2
+
3
+ describe Concensus do
4
+
5
+ describe "years" do
6
+
7
+ after { Concensus::configuration.year = 2010 }
8
+
9
+ it "should throw an error when a state is requested for 2011" do
10
+ expect do
11
+ Concensus::configuration.year = 2011
12
+ Concensus::State.find("CA")
13
+ end.to raise_error Concensus::NoResourceForYear
14
+ end
15
+
16
+ it "should throw an error when a county is requested for 2011" do
17
+ expect do
18
+ Concensus::configuration.year = 2011
19
+ Concensus::County.find("CA")
20
+ end.to raise_error Concensus::NoResourceForYear
21
+ end
22
+
23
+ it "should throw an error when a congressional district is requested for 2011" do
24
+ expect do
25
+ Concensus::configuration.year = 2011
26
+ Concensus::Congressional.find("CA")
27
+ end.to raise_error Concensus::NoResourceForYear
28
+ end
29
+
30
+ it "should throw an error when a zipcode is requested for 2011" do
31
+ expect do
32
+ Concensus::configuration.year = 2011
33
+ Concensus::Zipcode.find("CA")
34
+ end.to raise_error Concensus::NoResourceForYear
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,19 @@
1
+ require 'concensus'
2
+
3
+ describe Concensus do
4
+ describe "zipcodes" do
5
+
6
+ describe "2010" do
7
+ before { Concensus::configuration.year = 2010 }
8
+
9
+ it "should be able to find all zipcodes for a state" do
10
+ Concensus::Zipcode.find_all("CO").should be_instance_of(Array)
11
+ end
12
+
13
+ it "should be able to find one zipcode for a state" do
14
+ Concensus::Zipcode.find("CO", "80022").should be_instance_of(Concensus::Zipcode)
15
+ end
16
+ end
17
+
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concensus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70135306169280 !ruby/object:Gem::Requirement
16
+ requirement: &70200645061180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70135306169280
24
+ version_requirements: *70200645061180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &70135306168460 !ruby/object:Gem::Requirement
27
+ requirement: &70200645060720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70135306168460
35
+ version_requirements: *70200645060720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redcarpet
38
- requirement: &70135306167620 !ruby/object:Gem::Requirement
38
+ requirement: &70200645060160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,21 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70135306167620
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: &70135306166780 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: *70135306166780
46
+ version_requirements: *70200645060160
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: activesupport
60
- requirement: &70135306166200 !ruby/object:Gem::Requirement
49
+ requirement: &70200645059520 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ! '>='
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: '0'
66
55
  type: :runtime
67
56
  prerelease: false
68
- version_requirements: *70135306166200
57
+ version_requirements: *70200645059520
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: rubyzip
71
- requirement: &70135306165640 !ruby/object:Gem::Requirement
60
+ requirement: &70200645058760 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ! '>='
@@ -76,10 +65,10 @@ dependencies:
76
65
  version: '0'
77
66
  type: :runtime
78
67
  prerelease: false
79
- version_requirements: *70135306165640
68
+ version_requirements: *70200645058760
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: georuby
82
- requirement: &70135306164940 !ruby/object:Gem::Requirement
71
+ requirement: &70200645058220 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
74
  - - ! '>='
@@ -87,10 +76,10 @@ dependencies:
87
76
  version: '0'
88
77
  type: :runtime
89
78
  prerelease: false
90
- version_requirements: *70135306164940
79
+ version_requirements: *70200645058220
91
80
  - !ruby/object:Gem::Dependency
92
81
  name: dbf
93
- requirement: &70135306164140 !ruby/object:Gem::Requirement
82
+ requirement: &70200645057820 !ruby/object:Gem::Requirement
94
83
  none: false
95
84
  requirements:
96
85
  - - ! '>='
@@ -98,7 +87,7 @@ dependencies:
98
87
  version: '0'
99
88
  type: :runtime
100
89
  prerelease: false
101
- version_requirements: *70135306164140
90
+ version_requirements: *70200645057820
102
91
  description: ! '"A small tool for reading United States Census TIGER/Line Shapefiles."'
103
92
  email:
104
93
  - ad@mbecker.cc
@@ -123,6 +112,7 @@ files:
123
112
  - lib/concensus/state.rb
124
113
  - lib/concensus/state_legislative.rb
125
114
  - lib/concensus/version.rb
115
+ - lib/concensus/zipcode.rb
126
116
  - lib/geo_ruby/simple_features.rb
127
117
  - spec/concensus/accuracy_spec.rb
128
118
  - spec/concensus/configuration_spec.rb
@@ -132,6 +122,8 @@ files:
132
122
  - spec/concensus/school_spec.rb
133
123
  - spec/concensus/state_legislative_spec.rb
134
124
  - spec/concensus/state_spec.rb
125
+ - spec/concensus/year_spec.rb
126
+ - spec/concensus/zipcode_spec.rb
135
127
  homepage: https://github.com/adamjacobbecker/concensus
136
128
  licenses: []
137
129
  post_install_message:
@@ -165,4 +157,6 @@ test_files:
165
157
  - spec/concensus/school_spec.rb
166
158
  - spec/concensus/state_legislative_spec.rb
167
159
  - spec/concensus/state_spec.rb
160
+ - spec/concensus/year_spec.rb
161
+ - spec/concensus/zipcode_spec.rb
168
162
  has_rdoc: