us_geo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +75 -0
  4. data/README.md +154 -0
  5. data/Rakefile +18 -0
  6. data/db/migrate/20190221054200_create_regions.rb +16 -0
  7. data/db/migrate/20190221054300_create_divisions.rb +17 -0
  8. data/db/migrate/20190221054400_create_states.rb +20 -0
  9. data/db/migrate/20190221054490_create_designated_market_areas.rb +16 -0
  10. data/db/migrate/20190221054500_create_combined_statistical_areas.rb +20 -0
  11. data/db/migrate/20190221054600_create_core_based_statistical_areas.rb +24 -0
  12. data/db/migrate/20190221054650_create_metropolitan_divisions.rb +21 -0
  13. data/db/migrate/20190221054700_create_counties.rb +34 -0
  14. data/db/migrate/20190221054800_create_zctas.rb +23 -0
  15. data/db/migrate/20190221054900_create_zcta_counties.rb +22 -0
  16. data/db/migrate/20190221055000_create_urban_areas.rb +25 -0
  17. data/db/migrate/20190221055100_create_urban_area_counties.rb +22 -0
  18. data/db/migrate/20190221055200_create_zcta_urban_areas.rb +22 -0
  19. data/db/migrate/20190221060000_create_places.rb +28 -0
  20. data/db/migrate/20190221061000_create_place_counties.rb +18 -0
  21. data/db/migrate/20190221062000_create_zcta_places.rb +22 -0
  22. data/db/migrate/20190221063000_create_county_subdivisions.rb +25 -0
  23. data/lib/tasks/us_geo/us_geo.rake +43 -0
  24. data/lib/us_geo/base_record.rb +104 -0
  25. data/lib/us_geo/combined_statistical_area.rb +40 -0
  26. data/lib/us_geo/core_based_statistical_area.rb +57 -0
  27. data/lib/us_geo/county.rb +89 -0
  28. data/lib/us_geo/county_subdivision.rb +46 -0
  29. data/lib/us_geo/demographics.rb +25 -0
  30. data/lib/us_geo/designated_market_area.rb +30 -0
  31. data/lib/us_geo/division.rb +29 -0
  32. data/lib/us_geo/engine.rb +6 -0
  33. data/lib/us_geo/metropolitan_area.rb +18 -0
  34. data/lib/us_geo/metropolitan_division.rb +42 -0
  35. data/lib/us_geo/micropolitan_area.rb +18 -0
  36. data/lib/us_geo/place.rb +61 -0
  37. data/lib/us_geo/place_county.rb +28 -0
  38. data/lib/us_geo/region.rb +28 -0
  39. data/lib/us_geo/state.rb +56 -0
  40. data/lib/us_geo/urban_area.rb +66 -0
  41. data/lib/us_geo/urban_area_county.rb +68 -0
  42. data/lib/us_geo/urban_cluster.rb +18 -0
  43. data/lib/us_geo/urbanized_area.rb +18 -0
  44. data/lib/us_geo/version.rb +5 -0
  45. data/lib/us_geo/zcta.rb +63 -0
  46. data/lib/us_geo/zcta_county.rb +68 -0
  47. data/lib/us_geo/zcta_place.rb +68 -0
  48. data/lib/us_geo/zcta_urban_area.rb +68 -0
  49. data/lib/us_geo.rb +53 -0
  50. data/spec/spec_helper.rb +22 -0
  51. data/spec/us_geo/base_record_spec.rb +67 -0
  52. data/spec/us_geo/combined_statistical_area_spec.rb +33 -0
  53. data/spec/us_geo/core_based_statistical_area_spec.rb +56 -0
  54. data/spec/us_geo/county_spec.rb +130 -0
  55. data/spec/us_geo/county_subdivision_spec.rb +37 -0
  56. data/spec/us_geo/demographics_spec.rb +19 -0
  57. data/spec/us_geo/designated_market_area_spec.rb +29 -0
  58. data/spec/us_geo/division_spec.rb +37 -0
  59. data/spec/us_geo/metropolitan_division_spec.rb +41 -0
  60. data/spec/us_geo/place_county_spec.rb +39 -0
  61. data/spec/us_geo/place_spec.rb +71 -0
  62. data/spec/us_geo/region_spec.rb +36 -0
  63. data/spec/us_geo/state_spec.rb +70 -0
  64. data/spec/us_geo/urban_area_county_spec.rb +82 -0
  65. data/spec/us_geo/urban_area_spec.rb +98 -0
  66. data/spec/us_geo/zcta_county_spec.rb +82 -0
  67. data/spec/us_geo/zcta_place_spec.rb +82 -0
  68. data/spec/us_geo/zcta_spec.rb +99 -0
  69. data/spec/us_geo/zcta_urban_area_spec.rb +82 -0
  70. metadata +229 -0
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe USGeo::UrbanArea do
4
+
5
+ describe "associations" do
6
+ it "should have zctas" do
7
+ urban_area = USGeo::UrbanArea.new
8
+ urban_area.geoid = "00001"
9
+ expect{ urban_area.zctas }.to_not raise_error
10
+ expect{ urban_area.zcta_urban_areas }.to_not raise_error
11
+ expect(urban_area.zcta_urban_areas.build).to be_a(USGeo::ZctaUrbanArea)
12
+ end
13
+
14
+ it "should have counties" do
15
+ urban_area = USGeo::UrbanArea.new
16
+ urban_area.geoid = "00001"
17
+ expect{ urban_area.counties }.to_not raise_error
18
+ expect{ urban_area.urban_area_counties }.to_not raise_error
19
+ expect(urban_area.urban_area_counties.build).to be_a(USGeo::UrbanAreaCounty)
20
+ end
21
+
22
+ it "should have a primary county" do
23
+ urban_area = USGeo::UrbanArea.new
24
+ urban_area.geoid = "00001"
25
+ expect{ urban_area.primary_county }.to_not raise_error
26
+ expect(urban_area.build_primary_county).to be_a(USGeo::County)
27
+ end
28
+
29
+ it "should have a time zone via the primary county" do
30
+ urban_area = USGeo::UrbanArea.new
31
+ county = USGeo::County.new(time_zone_name: "America/Chicago")
32
+ urban_area.primary_county = county
33
+ expect(urban_area.time_zone).to eq ActiveSupport::TimeZone["America/Chicago"]
34
+ end
35
+
36
+ it "should have a state via the primary county" do
37
+ urban_area = USGeo::UrbanArea.new
38
+ state = USGeo::State.new
39
+ state.code = "XX"
40
+ county = USGeo::County.new(state_code: "XX")
41
+ county.state = state
42
+ urban_area.primary_county = county
43
+ expect(urban_area.state_code).to eq "XX"
44
+ expect(urban_area.state).to eq state
45
+ end
46
+
47
+ it "should have a core based statistical area via the primary county" do
48
+ urban_area = USGeo::UrbanArea.new
49
+ cbsa = USGeo::CoreBasedStatisticalArea.new
50
+ county = USGeo::County.new
51
+ county.core_based_statistical_area = cbsa
52
+ urban_area.primary_county = county
53
+ expect(urban_area.core_based_statistical_area).to eq cbsa
54
+ end
55
+
56
+ it "should have a designated market area via the primary county" do
57
+ urban_area = USGeo::UrbanArea.new
58
+ dma = USGeo::DesignatedMarketArea.new
59
+ county = USGeo::County.new
60
+ county.designated_market_area = dma
61
+ urban_area.primary_county = county
62
+ expect(urban_area.designated_market_area).to eq dma
63
+ end
64
+
65
+ end
66
+
67
+ describe "load" do
68
+ after { USGeo::UrbanArea.delete_all }
69
+
70
+ it "should load the fixture data" do
71
+ data = File.read(File.expand_path("../../data/dist/urban_areas.csv", __dir__))
72
+ stub_request(:get, "#{USGeo.base_data_uri}/urban_areas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
73
+ USGeo::UrbanArea.load!
74
+ expect(USGeo::UrbanArea.imported.count).to be > 3500
75
+ expect(USGeo::UrbanArea.removed.count).to eq 0
76
+
77
+ chicago = USGeo::UrbanizedArea.find("16264")
78
+ expect(chicago.name).to eq "Chicago, IL--IN Urbanized Area"
79
+ expect(chicago.short_name).to eq "Chicago, IL--IN"
80
+ expect(chicago.primary_county_geoid).to eq "17031"
81
+ expect(chicago.population).to be > 8_000_000
82
+ expect(chicago.housing_units).to be > 3_000_000
83
+ expect(chicago.land_area.round).to eq 2441
84
+ expect(chicago.water_area.round).to eq 43
85
+ expect(chicago.lat.round).to eq 42
86
+ expect(chicago.lng.round).to eq -88
87
+ expect(chicago.urbanized?).to eq true
88
+ expect(chicago.cluster?).to eq false
89
+
90
+ clinton = USGeo::UrbanCluster.find("17884")
91
+ expect(clinton.name).to eq "Clinton, IL Urban Cluster"
92
+ expect(clinton.short_name).to eq "Clinton, IL"
93
+ expect(chicago.urbanized?).to eq true
94
+ expect(chicago.cluster?).to eq false
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe USGeo::ZctaCounty do
4
+
5
+ describe "percentages" do
6
+ it "should return the percentage of the population of the zcta" do
7
+ zcta = USGeo::Zcta.new(population: 20_000)
8
+ zcta_county = zcta.zcta_counties.build(population: 5000)
9
+ expect(zcta_county.percent_zcta_population).to eq 0.25
10
+ end
11
+
12
+ it "should return the percentage of the land area of the zcta" do
13
+ zcta = USGeo::Zcta.new(land_area: 200)
14
+ zcta_county = zcta.zcta_counties.build(land_area: 50)
15
+ expect(zcta_county.percent_zcta_land_area).to eq 0.25
16
+ end
17
+
18
+ it "should return the percentage of the total area of the zcta" do
19
+ zcta = USGeo::Zcta.new(land_area: 150, water_area: 50)
20
+ zcta_county = zcta.zcta_counties.build(land_area: 30, water_area: 20)
21
+ expect(zcta_county.percent_zcta_total_area).to eq 0.25
22
+ end
23
+
24
+ it "should return the percentage of the population of the county" do
25
+ county = USGeo::County.new(population: 20_000)
26
+ zcta_county = county.zcta_counties.build(population: 5000)
27
+ expect(zcta_county.percent_county_population).to eq 0.25
28
+ end
29
+
30
+ it "should return the percentage of the land area of the county" do
31
+ county = USGeo::County.new(land_area: 200)
32
+ zcta_county = county.zcta_counties.build(land_area: 50)
33
+ expect(zcta_county.percent_county_land_area).to eq 0.25
34
+ end
35
+
36
+ it "should return the percentage of the total area of the county" do
37
+ county = USGeo::County.new(land_area: 150, water_area: 50)
38
+ zcta_county = county.zcta_counties.build(land_area: 30, water_area: 20)
39
+ expect(zcta_county.percent_county_total_area).to eq 0.25
40
+ end
41
+ end
42
+
43
+ describe "associations" do
44
+ it "should have a zcta" do
45
+ zcta_county = USGeo::ZctaCounty.new
46
+ zcta_county.zipcode = "60304"
47
+ zcta_county.county_geoid = "00001"
48
+ expect{ zcta_county.zcta }.to_not raise_error
49
+ expect(zcta_county.build_zcta).to be_a(USGeo::Zcta)
50
+ end
51
+
52
+ it "should have a county" do
53
+ zcta_county = USGeo::ZctaCounty.new
54
+ zcta_county.zipcode = "60304"
55
+ zcta_county.county_geoid = "00001"
56
+ expect{ zcta_county.county }.to_not raise_error
57
+ expect(zcta_county.build_county).to be_a(USGeo::County)
58
+ end
59
+ end
60
+
61
+ describe "load" do
62
+ after { USGeo::ZctaCounty.delete_all }
63
+
64
+ it "should load the fixture data" do
65
+ data = File.read(File.expand_path("../../data/dist/zcta_counties.csv", __dir__))
66
+ stub_request(:get, "#{USGeo.base_data_uri}/zcta_counties.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
67
+ USGeo::ZctaCounty.load!
68
+ expect(USGeo::ZctaCounty.imported.count).to be > 40_000
69
+ expect(USGeo::ZctaCounty.removed.count).to eq 0
70
+
71
+ zcta_counties = USGeo::ZctaCounty.where(zipcode: "00601")
72
+ expect(zcta_counties.size).to eq 2
73
+ expect(zcta_counties.collect(&:county_geoid)).to match_array(["72001", "72141"])
74
+ zcta_county = zcta_counties.detect{ |z| z.county_geoid == "72001"}
75
+ expect(zcta_county.population).to be > 10_000
76
+ expect(zcta_county.housing_units).to be > 4000
77
+ expect(zcta_county.land_area.round).to eq 63
78
+ expect(zcta_county.water_area.round(1)).to eq 0.3
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe USGeo::ZctaPlace do
4
+
5
+ describe "percentages" do
6
+ it "should return the percentage of the population of the zcta" do
7
+ zcta = USGeo::Zcta.new(population: 20_000)
8
+ zcta_place = zcta.zcta_places.build(population: 5000)
9
+ expect(zcta_place.percent_zcta_population).to eq 0.25
10
+ end
11
+
12
+ it "should return the percentage of the land area of the zcta" do
13
+ zcta = USGeo::Zcta.new(land_area: 200)
14
+ zcta_place = zcta.zcta_places.build(land_area: 50)
15
+ expect(zcta_place.percent_zcta_land_area).to eq 0.25
16
+ end
17
+
18
+ it "should return the percentage of the total area of the zcta" do
19
+ zcta = USGeo::Zcta.new(land_area: 150, water_area: 50)
20
+ zcta_place = zcta.zcta_places.build(land_area: 30, water_area: 20)
21
+ expect(zcta_place.percent_zcta_total_area).to eq 0.25
22
+ end
23
+
24
+ it "should return the percentage of the population of the zcta" do
25
+ place = USGeo::Place.new(population: 20_000)
26
+ zcta_place = place.zcta_places.build(population: 5000)
27
+ expect(zcta_place.percent_place_population).to eq 0.25
28
+ end
29
+
30
+ it "should return the percentage of the land area of the zcta" do
31
+ place = USGeo::Place.new(land_area: 200)
32
+ zcta_place = place.zcta_places.build(land_area: 50)
33
+ expect(zcta_place.percent_place_land_area).to eq 0.25
34
+ end
35
+
36
+ it "should return the percentage of the total area of the zcta" do
37
+ place = USGeo::Place.new(land_area: 150, water_area: 50)
38
+ zcta_place = place.zcta_places.build(land_area: 30, water_area: 20)
39
+ expect(zcta_place.percent_place_total_area).to eq 0.25
40
+ end
41
+ end
42
+
43
+ describe "associations" do
44
+ it "should have a zcta" do
45
+ zcta_place = USGeo::ZctaPlace.new
46
+ zcta_place.zipcode = "60304"
47
+ zcta_place.place_geoid = "0000001"
48
+ expect{ zcta_place.zcta }.to_not raise_error
49
+ expect(zcta_place.build_zcta).to be_a(USGeo::Zcta)
50
+ end
51
+
52
+ it "should have a place" do
53
+ zcta_place = USGeo::ZctaPlace.new
54
+ zcta_place.zipcode = "60304"
55
+ zcta_place.place_geoid = "0000001"
56
+ expect{ zcta_place.place }.to_not raise_error
57
+ expect(zcta_place.build_place).to be_a(USGeo::Place)
58
+ end
59
+ end
60
+
61
+ describe "load" do
62
+ after { USGeo::ZctaPlace.delete_all }
63
+
64
+ it "should load the fixture data" do
65
+ data = File.read(File.expand_path("../../data/dist/zcta_places.csv", __dir__))
66
+ stub_request(:get, "#{USGeo.base_data_uri}/zcta_places.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
67
+ USGeo::ZctaPlace.load!
68
+ expect(USGeo::ZctaPlace.imported.count).to be > 45_000
69
+ expect(USGeo::ZctaPlace.removed.count).to eq 0
70
+
71
+ zcta_places = USGeo::ZctaPlace.where(zipcode: "53211")
72
+ expect(zcta_places.size).to eq 3
73
+ expect(zcta_places.collect(&:place_geoid)).to match_array(["5553000", "5573725", "5586700"])
74
+ zcta_place = zcta_places.detect{ |z| z.place_geoid == "5553000"}
75
+ expect(zcta_place.population).to be > 15_000
76
+ expect(zcta_place.housing_units).to be > 7000
77
+ expect(zcta_place.land_area.round(1)).to eq 1.9
78
+ expect(zcta_place.water_area.round(3)).to eq 0.055
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe USGeo::Zcta do
4
+
5
+ describe "associations" do
6
+ it "should have a primary county" do
7
+ zcta = USGeo::Zcta.new
8
+ zcta.zipcode = "60304"
9
+ expect{ zcta.primary_county }.to_not raise_error
10
+ expect(zcta.build_primary_county).to be_a(USGeo::County)
11
+ end
12
+
13
+ it "should have counties" do
14
+ zcta = USGeo::Zcta.new
15
+ zcta.zipcode = "60304"
16
+ expect{ zcta.counties }.to_not raise_error
17
+ expect{ zcta.zcta_counties }.to_not raise_error
18
+ expect(zcta.zcta_counties.build).to be_a(USGeo::ZctaCounty)
19
+ end
20
+
21
+ it "should have a time zone via the primary county" do
22
+ zcta = USGeo::Zcta.new
23
+ zcta.zipcode = "60304"
24
+ county = USGeo::County.new(time_zone_name: "America/Chicago")
25
+ zcta.primary_county = county
26
+ expect(zcta.time_zone).to eq ActiveSupport::TimeZone["America/Chicago"]
27
+ end
28
+
29
+ it "should have a state via the primary county" do
30
+ zcta = USGeo::Zcta.new
31
+ zcta.zipcode = "60304"
32
+ state = USGeo::State.new
33
+ state.code = "XX"
34
+ county = USGeo::County.new(state_code: "XX")
35
+ county.state = state
36
+ zcta.primary_county = county
37
+ expect(zcta.state_code).to eq "XX"
38
+ expect(zcta.state).to eq state
39
+ end
40
+
41
+ it "should have a core based statistical area via the primary county" do
42
+ zcta = USGeo::Zcta.new
43
+ zcta.zipcode = "60304"
44
+ cbsa = USGeo::CoreBasedStatisticalArea.new
45
+ county = USGeo::County.new
46
+ county.core_based_statistical_area = cbsa
47
+ zcta.primary_county = county
48
+ expect(zcta.core_based_statistical_area).to eq cbsa
49
+ end
50
+
51
+ it "should have a designated market area via the primary county" do
52
+ zcta = USGeo::Zcta.new
53
+ zcta.zipcode = "60304"
54
+ dma = USGeo::DesignatedMarketArea.new
55
+ county = USGeo::County.new
56
+ county.designated_market_area = dma
57
+ zcta.primary_county = county
58
+ expect(zcta.designated_market_area).to eq dma
59
+ end
60
+
61
+ it "should have a primary urban area" do
62
+ zcta = USGeo::Zcta.new
63
+ zcta.zipcode = "60304"
64
+ expect{ zcta.primary_urban_area }.to_not raise_error
65
+ expect(zcta.build_primary_urban_area).to be_a(USGeo::UrbanArea)
66
+ end
67
+
68
+ it "should have urban areas" do
69
+ zcta = USGeo::Zcta.new
70
+ zcta.zipcode = "60304"
71
+ expect{ zcta.urban_areas }.to_not raise_error
72
+ expect{ zcta.zcta_urban_areas }.to_not raise_error
73
+ expect(zcta.zcta_urban_areas.build).to be_a(USGeo::ZctaUrbanArea)
74
+ end
75
+ end
76
+
77
+ describe "load" do
78
+ after { USGeo::Zcta.delete_all }
79
+
80
+ it "should load the fixture data" do
81
+ data = File.read(File.expand_path("../../data/dist/zctas.csv", __dir__))
82
+ stub_request(:get, "#{USGeo.base_data_uri}/zctas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
83
+ USGeo::Zcta.load!
84
+ expect(USGeo::Zcta.imported.count).to be > 30_000
85
+ expect(USGeo::Zcta.removed.count).to eq 0
86
+
87
+ zcta = USGeo::Zcta.find("60305")
88
+ expect(zcta.primary_county_geoid).to eq "17031"
89
+ expect(zcta.primary_urban_area_geoid).to eq "16264"
90
+ expect(zcta.population).to be > 10_000
91
+ expect(zcta.housing_units).to be > 4000
92
+ expect(zcta.land_area.round(1)).to eq 2.5
93
+ expect(zcta.water_area.round(3)).to eq 0.002
94
+ expect(zcta.lat.round).to eq 42
95
+ expect(zcta.lng.round).to eq -88
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe USGeo::ZctaUrbanArea do
4
+
5
+ describe "percentages" do
6
+ it "should return the percentage of the population of the zcta" do
7
+ zcta = USGeo::Zcta.new(population: 20_000)
8
+ zcta_urban_area = zcta.zcta_urban_areas.build(population: 5000)
9
+ expect(zcta_urban_area.percent_zcta_population).to eq 0.25
10
+ end
11
+
12
+ it "should return the percentage of the land area of the zcta" do
13
+ zcta = USGeo::Zcta.new(land_area: 200)
14
+ zcta_urban_area = zcta.zcta_urban_areas.build(land_area: 50)
15
+ expect(zcta_urban_area.percent_zcta_land_area).to eq 0.25
16
+ end
17
+
18
+ it "should return the percentage of the total area of the zcta" do
19
+ zcta = USGeo::Zcta.new(land_area: 150, water_area: 50)
20
+ zcta_urban_area = zcta.zcta_urban_areas.build(land_area: 30, water_area: 20)
21
+ expect(zcta_urban_area.percent_zcta_total_area).to eq 0.25
22
+ end
23
+
24
+ it "should return the percentage of the population of the urban area" do
25
+ urban_area = USGeo::UrbanArea.new(population: 20_000)
26
+ zcta_urban_area = urban_area.zcta_urban_areas.build(population: 5000)
27
+ expect(zcta_urban_area.percent_urban_area_population).to eq 0.25
28
+ end
29
+
30
+ it "should return the percentage of the land area of the urban area" do
31
+ urban_area = USGeo::UrbanArea.new(land_area: 200)
32
+ zcta_urban_area = urban_area.zcta_urban_areas.build(land_area: 50)
33
+ expect(zcta_urban_area.percent_urban_area_land_area).to eq 0.25
34
+ end
35
+
36
+ it "should return the percentage of the total area of the urban area" do
37
+ urban_area = USGeo::UrbanArea.new(land_area: 150, water_area: 50)
38
+ zcta_urban_area = urban_area.zcta_urban_areas.build(land_area: 30, water_area: 20)
39
+ expect(zcta_urban_area.percent_urban_area_total_area).to eq 0.25
40
+ end
41
+ end
42
+
43
+ describe "associations" do
44
+ it "should have a zcta" do
45
+ zcta_urban_area = USGeo::ZctaUrbanArea.new
46
+ zcta_urban_area.zipcode = "60304"
47
+ zcta_urban_area.urban_area_geoid = "00001"
48
+ expect{ zcta_urban_area.zcta }.to_not raise_error
49
+ expect(zcta_urban_area.build_zcta).to be_a(USGeo::Zcta)
50
+ end
51
+
52
+ it "should have an urban area" do
53
+ zcta_urban_area = USGeo::ZctaUrbanArea.new
54
+ zcta_urban_area.zipcode = "60304"
55
+ zcta_urban_area.urban_area_geoid = "00001"
56
+ expect{ zcta_urban_area.urban_area }.to_not raise_error
57
+ expect(zcta_urban_area.build_urban_area).to be_a(USGeo::UrbanArea)
58
+ end
59
+ end
60
+
61
+ describe "load" do
62
+ after { USGeo::ZctaUrbanArea.delete_all }
63
+
64
+ it "should load the fixture data" do
65
+ data = File.read(File.expand_path("../../data/dist/zcta_urban_areas.csv", __dir__))
66
+ stub_request(:get, "#{USGeo.base_data_uri}/zcta_urban_areas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
67
+ USGeo::ZctaUrbanArea.load!
68
+ expect(USGeo::ZctaUrbanArea.imported.count).to be > 15_000
69
+ expect(USGeo::ZctaUrbanArea.removed.count).to eq 0
70
+
71
+ zcta_urban_areas = USGeo::ZctaUrbanArea.where(urban_area_geoid: "39430")
72
+ expect(zcta_urban_areas.size).to eq 5
73
+ expect(zcta_urban_areas.collect(&:zipcode)).to match_array(["49423", "49424", "49434", "49460", "49464"])
74
+ zcta_urban_area = zcta_urban_areas.detect{ |z| z.zipcode == "49423"}
75
+ expect(zcta_urban_area.population).to be > 30_000
76
+ expect(zcta_urban_area.housing_units).to be > 12_000
77
+ expect(zcta_urban_area.land_area.round).to eq 20
78
+ expect(zcta_urban_area.water_area.round(1)).to eq 1.5
79
+ end
80
+ end
81
+
82
+ end
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: us_geo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Durand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: appraisal
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - README.md
120
+ - Rakefile
121
+ - db/migrate/20190221054200_create_regions.rb
122
+ - db/migrate/20190221054300_create_divisions.rb
123
+ - db/migrate/20190221054400_create_states.rb
124
+ - db/migrate/20190221054490_create_designated_market_areas.rb
125
+ - db/migrate/20190221054500_create_combined_statistical_areas.rb
126
+ - db/migrate/20190221054600_create_core_based_statistical_areas.rb
127
+ - db/migrate/20190221054650_create_metropolitan_divisions.rb
128
+ - db/migrate/20190221054700_create_counties.rb
129
+ - db/migrate/20190221054800_create_zctas.rb
130
+ - db/migrate/20190221054900_create_zcta_counties.rb
131
+ - db/migrate/20190221055000_create_urban_areas.rb
132
+ - db/migrate/20190221055100_create_urban_area_counties.rb
133
+ - db/migrate/20190221055200_create_zcta_urban_areas.rb
134
+ - db/migrate/20190221060000_create_places.rb
135
+ - db/migrate/20190221061000_create_place_counties.rb
136
+ - db/migrate/20190221062000_create_zcta_places.rb
137
+ - db/migrate/20190221063000_create_county_subdivisions.rb
138
+ - lib/tasks/us_geo/us_geo.rake
139
+ - lib/us_geo.rb
140
+ - lib/us_geo/base_record.rb
141
+ - lib/us_geo/combined_statistical_area.rb
142
+ - lib/us_geo/core_based_statistical_area.rb
143
+ - lib/us_geo/county.rb
144
+ - lib/us_geo/county_subdivision.rb
145
+ - lib/us_geo/demographics.rb
146
+ - lib/us_geo/designated_market_area.rb
147
+ - lib/us_geo/division.rb
148
+ - lib/us_geo/engine.rb
149
+ - lib/us_geo/metropolitan_area.rb
150
+ - lib/us_geo/metropolitan_division.rb
151
+ - lib/us_geo/micropolitan_area.rb
152
+ - lib/us_geo/place.rb
153
+ - lib/us_geo/place_county.rb
154
+ - lib/us_geo/region.rb
155
+ - lib/us_geo/state.rb
156
+ - lib/us_geo/urban_area.rb
157
+ - lib/us_geo/urban_area_county.rb
158
+ - lib/us_geo/urban_cluster.rb
159
+ - lib/us_geo/urbanized_area.rb
160
+ - lib/us_geo/version.rb
161
+ - lib/us_geo/zcta.rb
162
+ - lib/us_geo/zcta_county.rb
163
+ - lib/us_geo/zcta_place.rb
164
+ - lib/us_geo/zcta_urban_area.rb
165
+ - spec/spec_helper.rb
166
+ - spec/us_geo/base_record_spec.rb
167
+ - spec/us_geo/combined_statistical_area_spec.rb
168
+ - spec/us_geo/core_based_statistical_area_spec.rb
169
+ - spec/us_geo/county_spec.rb
170
+ - spec/us_geo/county_subdivision_spec.rb
171
+ - spec/us_geo/demographics_spec.rb
172
+ - spec/us_geo/designated_market_area_spec.rb
173
+ - spec/us_geo/division_spec.rb
174
+ - spec/us_geo/metropolitan_division_spec.rb
175
+ - spec/us_geo/place_county_spec.rb
176
+ - spec/us_geo/place_spec.rb
177
+ - spec/us_geo/region_spec.rb
178
+ - spec/us_geo/state_spec.rb
179
+ - spec/us_geo/urban_area_county_spec.rb
180
+ - spec/us_geo/urban_area_spec.rb
181
+ - spec/us_geo/zcta_county_spec.rb
182
+ - spec/us_geo/zcta_place_spec.rb
183
+ - spec/us_geo/zcta_spec.rb
184
+ - spec/us_geo/zcta_urban_area_spec.rb
185
+ homepage:
186
+ licenses:
187
+ - MIT
188
+ metadata: {}
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.7.6
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Collection of geographic data for the United States for use with ActiveRecord
209
+ test_files:
210
+ - spec/spec_helper.rb
211
+ - spec/us_geo/designated_market_area_spec.rb
212
+ - spec/us_geo/zcta_spec.rb
213
+ - spec/us_geo/county_spec.rb
214
+ - spec/us_geo/zcta_urban_area_spec.rb
215
+ - spec/us_geo/urban_area_county_spec.rb
216
+ - spec/us_geo/place_county_spec.rb
217
+ - spec/us_geo/place_spec.rb
218
+ - spec/us_geo/metropolitan_division_spec.rb
219
+ - spec/us_geo/state_spec.rb
220
+ - spec/us_geo/zcta_county_spec.rb
221
+ - spec/us_geo/core_based_statistical_area_spec.rb
222
+ - spec/us_geo/demographics_spec.rb
223
+ - spec/us_geo/county_subdivision_spec.rb
224
+ - spec/us_geo/zcta_place_spec.rb
225
+ - spec/us_geo/region_spec.rb
226
+ - spec/us_geo/urban_area_spec.rb
227
+ - spec/us_geo/combined_statistical_area_spec.rb
228
+ - spec/us_geo/division_spec.rb
229
+ - spec/us_geo/base_record_spec.rb