us_geo 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -0
  3. data/MIT_LICENSE.txt +21 -0
  4. data/README.md +77 -60
  5. data/UPDATING_TO_VERSION_2.md +172 -0
  6. data/VERSION +1 -0
  7. data/db/migrate/20190221054200_create_regions.rb +4 -2
  8. data/db/migrate/20190221054300_create_divisions.rb +4 -2
  9. data/db/migrate/20190221054400_create_states.rb +4 -2
  10. data/db/migrate/20190221054500_create_combined_statistical_areas.rb +4 -2
  11. data/db/migrate/20190221054600_create_core_based_statistical_areas.rb +4 -2
  12. data/db/migrate/20190221054650_create_metropolitan_divisions.rb +4 -2
  13. data/db/migrate/20190221054700_create_counties.rb +4 -3
  14. data/db/migrate/20190221054800_create_zctas.rb +4 -2
  15. data/db/migrate/20190221054900_create_zcta_counties.rb +4 -2
  16. data/db/migrate/20190221055000_create_urban_areas.rb +4 -2
  17. data/db/migrate/20190221055100_create_urban_area_counties.rb +4 -4
  18. data/db/migrate/20190221055200_create_zcta_urban_areas.rb +4 -4
  19. data/db/migrate/20190221060000_create_places.rb +4 -2
  20. data/db/migrate/20190221061000_create_place_counties.rb +4 -2
  21. data/db/migrate/20190221062000_create_zcta_places.rb +4 -4
  22. data/db/migrate/20190221063000_create_county_subdivisions.rb +4 -2
  23. data/db/migrate/20220722000000_allow_null_zcta_counties_demographics.rb +23 -0
  24. data/db/migrate/20220722000200_allow_null_zcta_places_demographics.rb +23 -0
  25. data/db/migrate/20230414000000_add_zcta_primary_place.rb +13 -0
  26. data/db/migrate/20230414000200_add_demographics_to_regions.rb +28 -0
  27. data/db/migrate/20230414000300_add_demographics_to_divisions.rb +28 -0
  28. data/db/migrate/20230414000400_add_demographics_to_states.rb +28 -0
  29. data/db/migrate/20230414000700_add_short_name_to_core_based_statistical_areas.rb +22 -0
  30. data/db/migrate/20230414000750_add_short_name_to_combined_statistical_areas.rb +22 -0
  31. data/db/migrate/20230414000800_create_zcta_mappings.rb +18 -0
  32. data/db/migrate/20230417000100_create_zcta_county_subdivisions.rb +22 -0
  33. data/db/migrate/20230417000200_add_unique_name_index_to_county_subdivisions.rb +26 -0
  34. data/db/migrate/20230417000250_add_zcta_primary_county_subdivision.rb +13 -0
  35. data/db/migrate/20230417000300_create_urban_area_county_subdivisions.rb +23 -0
  36. data/db/migrate/20230417000400_allow_null_urban_area_counties_demographics.rb +23 -0
  37. data/db/migrate/20230417000500_allow_null_zcta_urban_areas_demographics.rb +23 -0
  38. data/db/migrate/20230417000600_add_additional_time_zone_name_to_counties.rb +13 -0
  39. data/db/schema.rb +303 -0
  40. data/explorer_app/.gitattributes +7 -0
  41. data/explorer_app/.gitignore +34 -0
  42. data/explorer_app/Gemfile +38 -0
  43. data/explorer_app/Rakefile +6 -0
  44. data/explorer_app/app/assets/images/.keep +0 -0
  45. data/explorer_app/app/assets/stylesheets/application.css +1 -0
  46. data/explorer_app/app/controllers/application_controller.rb +64 -0
  47. data/explorer_app/app/controllers/combined_statistical_areas_controller.rb +12 -0
  48. data/explorer_app/app/controllers/concerns/.keep +0 -0
  49. data/explorer_app/app/controllers/core_based_statistical_areas_controller.rb +36 -0
  50. data/explorer_app/app/controllers/counties_controller.rb +22 -0
  51. data/explorer_app/app/controllers/county_subdivisions_controller.rb +23 -0
  52. data/explorer_app/app/controllers/divisions_controller.rb +27 -0
  53. data/explorer_app/app/controllers/home_controller.rb +6 -0
  54. data/explorer_app/app/controllers/metropolitan_divisions_controller.rb +27 -0
  55. data/explorer_app/app/controllers/places_controller.rb +23 -0
  56. data/explorer_app/app/controllers/regions_controller.rb +13 -0
  57. data/explorer_app/app/controllers/states_controller.rb +25 -0
  58. data/explorer_app/app/controllers/urban_areas_controller.rb +24 -0
  59. data/explorer_app/app/controllers/zctas_controller.rb +23 -0
  60. data/explorer_app/app/helpers/application_helper.rb +137 -0
  61. data/explorer_app/app/models/application_record.rb +3 -0
  62. data/explorer_app/app/models/concerns/.keep +0 -0
  63. data/explorer_app/app/views/combined_statistical_areas/_table.html.erb +18 -0
  64. data/explorer_app/app/views/combined_statistical_areas/index.html.erb +7 -0
  65. data/explorer_app/app/views/combined_statistical_areas/show.html.erb +52 -0
  66. data/explorer_app/app/views/core_based_statistical_areas/_table.html.erb +32 -0
  67. data/explorer_app/app/views/core_based_statistical_areas/index.html.erb +19 -0
  68. data/explorer_app/app/views/core_based_statistical_areas/show.html.erb +60 -0
  69. data/explorer_app/app/views/counties/_table.html.erb +64 -0
  70. data/explorer_app/app/views/counties/show.html.erb +96 -0
  71. data/explorer_app/app/views/county_subdivisions/_table.html.erb +48 -0
  72. data/explorer_app/app/views/county_subdivisions/show.html.erb +84 -0
  73. data/explorer_app/app/views/divisions/_table.html.erb +24 -0
  74. data/explorer_app/app/views/divisions/index.html.erb +3 -0
  75. data/explorer_app/app/views/divisions/show.html.erb +3 -0
  76. data/explorer_app/app/views/home/index.html.erb +23 -0
  77. data/explorer_app/app/views/layouts/application.html.erb +34 -0
  78. data/explorer_app/app/views/metropolitan_divisions/_table.html.erb +42 -0
  79. data/explorer_app/app/views/metropolitan_divisions/index.html.erb +8 -0
  80. data/explorer_app/app/views/metropolitan_divisions/show.html.erb +46 -0
  81. data/explorer_app/app/views/places/_table.html.erb +47 -0
  82. data/explorer_app/app/views/places/show.html.erb +92 -0
  83. data/explorer_app/app/views/regions/_table.html.erb +18 -0
  84. data/explorer_app/app/views/regions/index.html.erb +7 -0
  85. data/explorer_app/app/views/regions/show.html.erb +3 -0
  86. data/explorer_app/app/views/shared/_breadcrumbs.html.erb +13 -0
  87. data/explorer_app/app/views/shared/_demographics_cells.html.erb +5 -0
  88. data/explorer_app/app/views/shared/_demographics_headers.html.erb +5 -0
  89. data/explorer_app/app/views/states/_table.html.erb +31 -0
  90. data/explorer_app/app/views/states/index.html.erb +7 -0
  91. data/explorer_app/app/views/states/show.html.erb +54 -0
  92. data/explorer_app/app/views/urban_areas/_table.html.erb +45 -0
  93. data/explorer_app/app/views/urban_areas/index.html.erb +19 -0
  94. data/explorer_app/app/views/urban_areas/show.html.erb +68 -0
  95. data/explorer_app/app/views/zctas/_table.html.erb +60 -0
  96. data/explorer_app/app/views/zctas/show.html.erb +104 -0
  97. data/explorer_app/bin/bundle +109 -0
  98. data/explorer_app/bin/rails +4 -0
  99. data/explorer_app/bin/rake +4 -0
  100. data/explorer_app/bin/setup +33 -0
  101. data/explorer_app/config/application.rb +37 -0
  102. data/explorer_app/config/boot.rb +3 -0
  103. data/explorer_app/config/database.yml +13 -0
  104. data/explorer_app/config/environment.rb +5 -0
  105. data/explorer_app/config/environments/development.rb +59 -0
  106. data/explorer_app/config/initializers/filter_parameter_logging.rb +8 -0
  107. data/explorer_app/config/locales/en.yml +2 -0
  108. data/explorer_app/config/puma.rb +43 -0
  109. data/explorer_app/config/routes.rb +56 -0
  110. data/explorer_app/config.ru +6 -0
  111. data/explorer_app/db/seeds.rb +7 -0
  112. data/explorer_app/lib/assets/.keep +0 -0
  113. data/explorer_app/lib/tasks/.keep +0 -0
  114. data/explorer_app/log/.keep +0 -0
  115. data/explorer_app/public/404.html +67 -0
  116. data/explorer_app/public/422.html +67 -0
  117. data/explorer_app/public/500.html +66 -0
  118. data/explorer_app/public/apple-touch-icon-precomposed.png +0 -0
  119. data/explorer_app/public/apple-touch-icon.png +0 -0
  120. data/explorer_app/public/favicon.ico +0 -0
  121. data/explorer_app/public/robots.txt +1 -0
  122. data/explorer_app/tmp/.keep +0 -0
  123. data/explorer_app/tmp/pids/.keep +0 -0
  124. data/lib/tasks/us_geo/us_geo.rake +44 -3
  125. data/lib/us_geo/area.rb +44 -0
  126. data/lib/us_geo/base_record.rb +22 -16
  127. data/lib/us_geo/combined_statistical_area.rb +18 -8
  128. data/lib/us_geo/core_based_statistical_area.rb +24 -12
  129. data/lib/us_geo/county.rb +67 -16
  130. data/lib/us_geo/county_subdivision.rb +43 -7
  131. data/lib/us_geo/division.rb +17 -7
  132. data/lib/us_geo/metropolitan_area.rb +1 -5
  133. data/lib/us_geo/metropolitan_division.rb +17 -9
  134. data/lib/us_geo/micropolitan_area.rb +1 -5
  135. data/lib/us_geo/place.rb +61 -11
  136. data/lib/us_geo/place_county.rb +1 -4
  137. data/lib/us_geo/population.rb +26 -0
  138. data/lib/us_geo/region.rb +18 -8
  139. data/lib/us_geo/state.rb +32 -11
  140. data/lib/us_geo/urban_area.rb +46 -16
  141. data/lib/us_geo/urban_area_county.rb +4 -21
  142. data/lib/us_geo/urban_area_county_subdivision.rb +51 -0
  143. data/lib/us_geo/urban_cluster.rb +1 -5
  144. data/lib/us_geo/urbanized_area.rb +1 -5
  145. data/lib/us_geo/version.rb +1 -1
  146. data/lib/us_geo/zcta.rb +90 -13
  147. data/lib/us_geo/zcta_county.rb +5 -22
  148. data/lib/us_geo/zcta_county_subdivision.rb +51 -0
  149. data/lib/us_geo/zcta_mapping.rb +35 -0
  150. data/lib/us_geo/zcta_place.rb +5 -12
  151. data/lib/us_geo/zcta_urban_area.rb +3 -20
  152. data/lib/us_geo.rb +34 -31
  153. data/us_geo.gemspec +36 -0
  154. metadata +125 -129
  155. data/Gemfile +0 -5
  156. data/Gemfile.lock +0 -75
  157. data/Rakefile +0 -18
  158. data/db/migrate/20190221054490_create_designated_market_areas.rb +0 -16
  159. data/lib/us_geo/demographics.rb +0 -25
  160. data/lib/us_geo/designated_market_area.rb +0 -30
  161. data/spec/spec_helper.rb +0 -22
  162. data/spec/us_geo/base_record_spec.rb +0 -67
  163. data/spec/us_geo/combined_statistical_area_spec.rb +0 -33
  164. data/spec/us_geo/core_based_statistical_area_spec.rb +0 -56
  165. data/spec/us_geo/county_spec.rb +0 -131
  166. data/spec/us_geo/county_subdivision_spec.rb +0 -37
  167. data/spec/us_geo/demographics_spec.rb +0 -19
  168. data/spec/us_geo/designated_market_area_spec.rb +0 -29
  169. data/spec/us_geo/division_spec.rb +0 -37
  170. data/spec/us_geo/metropolitan_division_spec.rb +0 -41
  171. data/spec/us_geo/place_county_spec.rb +0 -39
  172. data/spec/us_geo/place_spec.rb +0 -71
  173. data/spec/us_geo/region_spec.rb +0 -36
  174. data/spec/us_geo/state_spec.rb +0 -70
  175. data/spec/us_geo/urban_area_county_spec.rb +0 -82
  176. data/spec/us_geo/urban_area_spec.rb +0 -98
  177. data/spec/us_geo/zcta_county_spec.rb +0 -82
  178. data/spec/us_geo/zcta_place_spec.rb +0 -82
  179. data/spec/us_geo/zcta_spec.rb +0 -99
  180. data/spec/us_geo/zcta_urban_area_spec.rb +0 -82
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::State do
4
-
5
- describe "associations" do
6
- it "should belong to a region" do
7
- state = USGeo::State.new
8
- state.code = "XX"
9
- expect{ state.region }.to_not raise_error
10
- expect(state.build_region).to be_a(USGeo::Region)
11
- end
12
-
13
- it "should belong to a division" do
14
- state = USGeo::State.new
15
- state.code = "XX"
16
- expect{ state.division }.to_not raise_error
17
- expect(state.build_division).to be_a(USGeo::Division)
18
- end
19
-
20
- it "should have counties" do
21
- state = USGeo::State.new
22
- state.code = "XX"
23
- expect{ state.counties }.to_not raise_error
24
- expect(state.counties.build).to be_a(USGeo::County)
25
- end
26
-
27
- it "should have places" do
28
- state = USGeo::State.new
29
- state.code = "XX"
30
- expect{ state.places }.to_not raise_error
31
- expect(state.places.build).to be_a(USGeo::Place)
32
- end
33
- end
34
-
35
- describe "load" do
36
- after { USGeo::State.delete_all }
37
-
38
- it "should load the fixture data" do
39
- data = File.read(File.expand_path("../../data/dist/states.csv", __dir__))
40
- stub_request(:get, "#{USGeo.base_data_uri}/states.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
41
- USGeo::State.load!
42
- expect(USGeo::State.imported.count).to eq 59
43
- expect(USGeo::State.removed.count).to eq 0
44
-
45
- illinois = USGeo::State.find("IL")
46
- expect(illinois.name).to eq "Illinois"
47
- expect(illinois.type).to eq "state"
48
- expect(illinois.fips).to eq "17"
49
- expect(illinois.region_id).to eq 2
50
- expect(illinois.division_id).to eq 3
51
- end
52
- end
53
-
54
- describe "type" do
55
- it "should detect the state type" do
56
- expect(USGeo::State.new(type: "state").state?).to eq true
57
- expect(USGeo::State.new(type: "territory").state?).to eq false
58
- expect(USGeo::State.new(type: "district").state?).to eq false
59
-
60
- expect(USGeo::State.new(type: "state").district?).to eq false
61
- expect(USGeo::State.new(type: "territory").district?).to eq false
62
- expect(USGeo::State.new(type: "district").district?).to eq true
63
-
64
- expect(USGeo::State.new(type: "state").territory?).to eq false
65
- expect(USGeo::State.new(type: "territory").territory?).to eq true
66
- expect(USGeo::State.new(type: "district").territory?).to eq false
67
- end
68
- end
69
-
70
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::UrbanAreaCounty do
4
-
5
- describe "percentages" do
6
- it "should return the percentage of the population of the urban area" do
7
- urban_area = USGeo::UrbanArea.new(population: 20_000)
8
- urban_area_county = urban_area.urban_area_counties.build(population: 5000)
9
- expect(urban_area_county.percent_urban_area_population).to eq 0.25
10
- end
11
-
12
- it "should return the percentage of the land area of the urban area" do
13
- urban_area = USGeo::UrbanArea.new(land_area: 200)
14
- urban_area_county = urban_area.urban_area_counties.build(land_area: 50)
15
- expect(urban_area_county.percent_urban_area_land_area).to eq 0.25
16
- end
17
-
18
- it "should return the percentage of the total area of the urban area" do
19
- urban_area = USGeo::UrbanArea.new(land_area: 150, water_area: 50)
20
- urban_area_county = urban_area.urban_area_counties.build(land_area: 30, water_area: 20)
21
- expect(urban_area_county.percent_urban_area_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
- urban_area_county = county.urban_area_counties.build(population: 5000)
27
- expect(urban_area_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
- urban_area_county = county.urban_area_counties.build(land_area: 50)
33
- expect(urban_area_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
- urban_area_county = county.urban_area_counties.build(land_area: 30, water_area: 20)
39
- expect(urban_area_county.percent_county_total_area).to eq 0.25
40
- end
41
- end
42
-
43
- describe "associations" do
44
- it "should have a county" do
45
- urban_area_county = USGeo::UrbanAreaCounty.new
46
- urban_area_county.county_geoid = "60304"
47
- urban_area_county.urban_area_geoid = "00001"
48
- expect{ urban_area_county.county }.to_not raise_error
49
- expect(urban_area_county.build_county).to be_a(USGeo::County)
50
- end
51
-
52
- it "should have an urban area" do
53
- urban_area_county = USGeo::UrbanAreaCounty.new
54
- urban_area_county.county_geoid = "60304"
55
- urban_area_county.urban_area_geoid = "00001"
56
- expect{ urban_area_county.urban_area }.to_not raise_error
57
- expect(urban_area_county.build_urban_area).to be_a(USGeo::UrbanArea)
58
- end
59
- end
60
-
61
- describe "load" do
62
- after { USGeo::UrbanAreaCounty.delete_all }
63
-
64
- it "should load the fixture data" do
65
- data = File.read(File.expand_path("../../data/dist/urban_area_counties.csv", __dir__))
66
- stub_request(:get, "#{USGeo.base_data_uri}/urban_area_counties.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
67
- USGeo::UrbanAreaCounty.load!
68
- expect(USGeo::UrbanAreaCounty.imported.count).to be > 4000
69
- expect(USGeo::UrbanAreaCounty.removed.count).to eq 0
70
-
71
- urban_area_counties = USGeo::UrbanAreaCounty.where(urban_area_geoid: "39430")
72
- expect(urban_area_counties.size).to eq 2
73
- expect(urban_area_counties.collect(&:county_geoid)).to match_array(["26005", "26139"])
74
- urban_area_county = urban_area_counties.detect{ |z| z.county_geoid == "26005"}
75
- expect(urban_area_county.population).to be > 9000
76
- expect(urban_area_county.housing_units).to be > 4000
77
- expect(urban_area_county.land_area.round).to eq 8
78
- expect(urban_area_county.water_area.round(2)).to eq 0.03
79
- end
80
- end
81
-
82
- end
@@ -1,98 +0,0 @@
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
@@ -1,82 +0,0 @@
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
@@ -1,82 +0,0 @@
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
@@ -1,99 +0,0 @@
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
@@ -1,82 +0,0 @@
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