us_geo 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module USGeo
4
-
5
- # Media market (DMA) as defined by the Nielsen Company.
6
- class DesignatedMarketArea < BaseRecord
7
-
8
- self.primary_key = "code"
9
-
10
- has_many :counties, foreign_key: :dma_code, inverse_of: :designated_market_area
11
-
12
- validates :code, length: {is: 3}
13
- validates :name, length: {maximum: 60}
14
-
15
- class << self
16
- def load!(uri = nil)
17
- location = data_uri(uri || "dmas.csv")
18
-
19
- import! do
20
- load_data_file(location) do |row|
21
- load_record!(code: row["Code"]) do |record|
22
- record.name = row["Name"]
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- end
30
- end
data/spec/spec_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- require "bundler/setup"
2
- require_relative "../lib/us_geo"
3
-
4
- require "active_record"
5
- require "webmock/rspec"
6
-
7
- RSpec.configure do |config|
8
- # Enable flags like --only-failures and --next-failure
9
- config.example_status_persistence_file_path = ".rspec_status"
10
-
11
- config.expect_with :rspec do |c|
12
- c.syntax = :expect
13
- end
14
- end
15
-
16
- ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
17
-
18
- Dir.glob(File.expand_path("../db/migrate/*.rb", __dir__)).each do |path|
19
- require(path)
20
- class_name = File.basename(path).sub(/\.rb/, '').split('_', 2).last.camelcase
21
- class_name.constantize.migrate(:up)
22
- end
@@ -1,67 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe USGeo::BaseRecord do
4
-
5
- describe "status" do
6
- it "should be marked as imported" do
7
- record = USGeo::County.new(status: 1)
8
- expect(record.imported?).to eq true
9
- expect(record.removed?).to eq false
10
- expect(record.manual?).to eq false
11
- end
12
-
13
- it "should be marked as removed" do
14
- record = USGeo::County.new(status: -1)
15
- expect(record.imported?).to eq false
16
- expect(record.removed?).to eq true
17
- expect(record.manual?).to eq false
18
- end
19
-
20
- it "should be marked as manual" do
21
- record = USGeo::County.new(status: 0)
22
- expect(record.imported?).to eq false
23
- expect(record.removed?).to eq false
24
- expect(record.manual?).to eq true
25
- end
26
- end
27
-
28
- describe "load!" do
29
- after { USGeo::Region.delete_all }
30
-
31
- it "should mark previously imported records as removed" do
32
- data = File.read(File.expand_path("../../data/dist/divisions.csv", __dir__))
33
- stub_request(:get, "#{USGeo.base_data_uri}/divisions.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
34
-
35
- midwest = USGeo::Region.new
36
- midwest.id = 2
37
- midwest.name = "Northwest Territory"
38
- midwest.status = USGeo::Region::STATUS_MANUAL
39
- midwest.save!
40
-
41
- other = USGeo::Region.new
42
- other.id = 90
43
- other.name = "Other"
44
- other.status = USGeo::Region::STATUS_IMPORTED
45
- other.save!
46
-
47
- manual = USGeo::Region.new
48
- manual.id = 80
49
- manual.name = "Manual"
50
- manual.status = USGeo::Region::STATUS_MANUAL
51
- manual.save!
52
-
53
- sleep(1)
54
- USGeo::Region.load!
55
-
56
- midwest.reload
57
- other.reload
58
- manual.reload
59
-
60
- expect(midwest.status).to eq USGeo::Region::STATUS_IMPORTED
61
- expect(midwest.name).to eq "Midwest"
62
- expect(other.status).to eq USGeo::Region::STATUS_REMOVED
63
- expect(manual.status).to eq USGeo::Region::STATUS_MANUAL
64
- end
65
- end
66
-
67
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::CombinedStatisticalArea do
4
-
5
- describe "associations" do
6
- it "should have core_based_statistical_areas" do
7
- csa = USGeo::CombinedStatisticalArea.new
8
- csa.geoid = "001"
9
- expect{ csa.core_based_statistical_areas }.to_not raise_error
10
- expect(csa.core_based_statistical_areas.build).to be_a(USGeo::CoreBasedStatisticalArea)
11
- end
12
- end
13
-
14
- describe "load" do
15
- after { USGeo::CombinedStatisticalArea.delete_all }
16
-
17
- it "should load the fixture data" do
18
- data = File.read(File.expand_path("../../data/dist/combined_statistical_areas.csv", __dir__))
19
- stub_request(:get, "#{USGeo.base_data_uri}/combined_statistical_areas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
20
- USGeo::CombinedStatisticalArea.load!
21
- expect(USGeo::CombinedStatisticalArea.imported.count).to be > 150
22
- expect(USGeo::CombinedStatisticalArea.removed.count).to eq 0
23
-
24
- chicagoland = USGeo::CombinedStatisticalArea.find("176")
25
- expect(chicagoland.name).to eq "Chicago-Naperville, IL-IN-WI"
26
- expect(chicagoland.population).to be > 8_000_000
27
- expect(chicagoland.housing_units).to be > 3_000_000
28
- expect(chicagoland.land_area.round).to eq 10636
29
- expect(chicagoland.water_area.round).to eq 2431
30
- end
31
- end
32
-
33
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::CoreBasedStatisticalArea do
4
-
5
- describe "associations" do
6
- it "should have a combined statistical area" do
7
- core_based_statistical_area = USGeo::CoreBasedStatisticalArea.new
8
- core_based_statistical_area.geoid = "00001"
9
- expect{ core_based_statistical_area.combined_statistical_area }.to_not raise_error
10
- expect(core_based_statistical_area.build_combined_statistical_area).to be_a(USGeo::CombinedStatisticalArea)
11
- end
12
-
13
- it "should have counties" do
14
- core_based_statistical_area = USGeo::CoreBasedStatisticalArea.new
15
- core_based_statistical_area.geoid = "00001"
16
- expect{ core_based_statistical_area.counties }.to_not raise_error
17
- expect(core_based_statistical_area.counties.build).to be_a(USGeo::County)
18
- end
19
-
20
- it "should have metropolitan divisions" do
21
- core_based_statistical_area = USGeo::CoreBasedStatisticalArea.new
22
- core_based_statistical_area.geoid = "00001"
23
- expect{ core_based_statistical_area.metropolitan_divisions }.to_not raise_error
24
- expect(core_based_statistical_area.metropolitan_divisions.build).to be_a(USGeo::MetropolitanDivision)
25
- end
26
- end
27
-
28
- describe "load" do
29
- after { USGeo::CoreBasedStatisticalArea.delete_all }
30
-
31
- it "should load the fixture data" do
32
- data = File.read(File.expand_path("../../data/dist/core_based_statistical_areas.csv", __dir__))
33
- stub_request(:get, "#{USGeo.base_data_uri}/core_based_statistical_areas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
34
- USGeo::CoreBasedStatisticalArea.load!
35
- expect(USGeo::CoreBasedStatisticalArea.imported.count).to be > 900
36
- expect(USGeo::CoreBasedStatisticalArea.removed.count).to eq 0
37
-
38
- chicagoarea = USGeo::CoreBasedStatisticalArea.find("16980")
39
- expect(chicagoarea).to be_a(USGeo::MetropolitanArea)
40
- expect(chicagoarea.name).to eq "Chicago-Naperville-Elgin, IL-IN-WI"
41
- expect(chicagoarea.csa_geoid).to eq "176"
42
- expect(chicagoarea.population).to be > 8_000_000
43
- expect(chicagoarea.housing_units).to be > 3_000_000
44
- expect(chicagoarea.land_area.round).to eq 7197
45
- expect(chicagoarea.water_area.round).to eq 2382
46
- expect(chicagoarea.lat.round).to eq 42
47
- expect(chicagoarea.lng.round).to eq -88
48
-
49
- centralia = USGeo::CoreBasedStatisticalArea.find("16460")
50
- expect(centralia.population).to be < 50_000
51
- expect(centralia).to be_a(USGeo::MicropolitanArea)
52
- expect(centralia.name).to eq "Centralia, IL"
53
- end
54
- end
55
-
56
- end
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::County do
4
-
5
- describe "associations" do
6
- it "should have a state" do
7
- county = USGeo::County.new
8
- county.geoid = "00001"
9
- expect{ county.state }.to_not raise_error
10
- expect(county.build_state).to be_a(USGeo::State)
11
- end
12
-
13
- it "should have a core_based_statistical_area" do
14
- county = USGeo::County.new
15
- county.geoid = "00001"
16
- expect{ county.core_based_statistical_area }.to_not raise_error
17
- expect(county.build_core_based_statistical_area).to be_a(USGeo::CoreBasedStatisticalArea)
18
- end
19
-
20
- it "should have a metropolitan area if the core_based_statistical_area is metropolitan" do
21
- county = USGeo::County.new
22
- expect(county.metropolitan_area).to eq nil
23
- county.core_based_statistical_area = USGeo::MicropolitanArea.new
24
- expect(county.metropolitan_area).to eq nil
25
- metro_area = USGeo::MetropolitanArea.new
26
- county.core_based_statistical_area = metro_area
27
- expect(county.metropolitan_area).to eq metro_area
28
- end
29
-
30
- it "should have a metropolitan division" do
31
- county = USGeo::County.new
32
- county.geoid = "00001"
33
- expect{ county.metropolitan_division }.to_not raise_error
34
- expect(county.build_metropolitan_division).to be_a(USGeo::MetropolitanDivision)
35
- end
36
-
37
- it "should have zctas" do
38
- county = USGeo::County.new
39
- county.geoid = "00001"
40
- expect{ county.zctas }.to_not raise_error
41
- expect{ county.zcta_counties }.to_not raise_error
42
- expect(county.zcta_counties.build).to be_a(USGeo::ZctaCounty)
43
- end
44
-
45
- it "should have urban areas" do
46
- county = USGeo::County.new
47
- county.geoid = "00001"
48
- expect{ county.urban_areas }.to_not raise_error
49
- expect{ county.urban_area_counties }.to_not raise_error
50
- expect(county.urban_area_counties.build).to be_a(USGeo::UrbanAreaCounty)
51
- end
52
-
53
- it "should have places" do
54
- county = USGeo::County.new
55
- county.geoid = "00001"
56
- expect{ county.places }.to_not raise_error
57
- expect{ county.place_counties }.to_not raise_error
58
- expect(county.place_counties.build).to be_a(USGeo::PlaceCounty)
59
- end
60
-
61
- it "should have subdivisions" do
62
- county = USGeo::County.new
63
- county.geoid = "00001"
64
- expect{ county.subdivisions }.to_not raise_error
65
- expect(county.subdivisions.build).to be_a(USGeo::CountySubdivision)
66
- end
67
-
68
- it "should have a designated market area" do
69
- county = USGeo::County.new
70
- county.geoid = "00001"
71
- expect{ county.designated_market_area }.to_not raise_error
72
- expect(county.build_designated_market_area).to be_a(USGeo::DesignatedMarketArea)
73
- end
74
- end
75
-
76
- describe "load" do
77
- after { USGeo::County.delete_all }
78
-
79
- it "should load the fixture data" do
80
- data = File.read(File.expand_path("../../data/dist/counties.csv", __dir__))
81
- stub_request(:get, "#{USGeo.base_data_uri}/counties.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
82
- USGeo::County.load!
83
- expect(USGeo::County.imported.count).to be > 3000
84
- expect(USGeo::County.removed.count).to eq 0
85
-
86
- cook = USGeo::County.find("17031")
87
- expect(cook.name).to eq "Cook County"
88
- expect(cook.short_name).to eq "Cook"
89
- expect(cook.dma_code).to eq "602"
90
- expect(cook.cbsa_geoid).to eq "16980"
91
- expect(cook.metropolitan_division_geoid).to eq "16984"
92
- expect(cook.state_code).to eq "IL"
93
- expect(cook.state_fips).to eq "17"
94
- expect(cook.county_fips).to eq "031"
95
- expect(cook.fips_class_code).to eq "H1"
96
- expect(cook.time_zone_name).to eq "America/Chicago"
97
- expect(cook.central?).to eq true
98
- expect(cook.population).to be > 5_000_000
99
- expect(cook.housing_units).to be > 2_000_000
100
- expect(cook.land_area.round).to eq 945
101
- expect(cook.water_area.round).to eq 690
102
- expect(cook.lat.round).to eq 42
103
- expect(cook.lng.round).to eq -88
104
-
105
- clinton = USGeo::County.find("17027")
106
- expect(clinton.name).to eq "Clinton County"
107
- expect(clinton.central?).to eq false
108
- end
109
- end
110
-
111
- describe "attributes" do
112
- it "should have a state FIPS code" do
113
- county = USGeo::County.new
114
- county.geoid = "17031"
115
- expect(county.state_fips).to eq "17"
116
- end
117
-
118
- it "should have a county FIPS code" do
119
- county = USGeo::County.new
120
- county.geoid = "17031"
121
- expect(county.county_fips).to eq "031"
122
- end
123
-
124
- it "should have a time zone" do
125
- county = USGeo::County.new(time_zone_name: "America/Chicago")
126
- expect(county.time_zone).to be_a(ActiveSupport::TimeZone)
127
- expect(county.time_zone.name).to eq "America/Chicago"
128
- end
129
- end
130
-
131
- end
@@ -1,37 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe USGeo::CountySubdivision do
4
-
5
- describe "associations" do
6
- it "should have a county" do
7
- subdivision = USGeo::CountySubdivision.new
8
- subdivision.geoid = "0000000001"
9
- expect{ subdivision.county }.to_not raise_error
10
- expect(subdivision.build_county).to be_a(USGeo::County)
11
- end
12
- end
13
-
14
- describe "load" do
15
- after { USGeo::CountySubdivision.delete_all }
16
-
17
- it "should load the fixture data" do
18
- data = File.read(File.expand_path("../../data/dist/county_subdivisions.csv", __dir__))
19
- stub_request(:get, "#{USGeo.base_data_uri}/county_subdivisions.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
20
- USGeo::CountySubdivision.load!
21
- expect(USGeo::CountySubdivision.imported.count).to be > 35_000
22
- expect(USGeo::CountySubdivision.removed.count).to eq 0
23
-
24
- subdivision = USGeo::CountySubdivision.find("2600545180")
25
- expect(subdivision.name).to eq "Township of Laketown"
26
- expect(subdivision.county_geoid).to eq "26005"
27
- expect(subdivision.population).to be > 5000
28
- expect(subdivision.housing_units).to be > 2000
29
- expect(subdivision.fips_class_code).to eq "T1"
30
- expect(subdivision.land_area.round).to eq 22
31
- expect(subdivision.water_area.round(1)).to eq 0.1
32
- expect(subdivision.lat.round).to eq 43
33
- expect(subdivision.lng.round).to eq -86
34
- end
35
- end
36
-
37
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe USGeo::Demographics do
4
-
5
- let(:record) { USGeo::County.new(population: 90_000, land_area: 45.0, water_area: 5.0) }
6
-
7
- it "should return the population density of the land area" do
8
- expect(record.population_density).to eq 2000.0
9
- end
10
-
11
- it "should return the total area" do
12
- expect(record.total_area).to eq 50.0
13
- end
14
-
15
- it "should return the percent of land to water" do
16
- expect(record.percent_land).to eq 0.9
17
- end
18
-
19
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::DesignatedMarketArea do
4
-
5
- describe "associations" do
6
- it "should have counties" do
7
- division = USGeo::DesignatedMarketArea.new
8
- division.id = 1
9
- expect{ division.counties }.to_not raise_error
10
- expect(division.counties.build).to be_a(USGeo::County)
11
- end
12
- end
13
-
14
- describe "load" do
15
- after { USGeo::DesignatedMarketArea.delete_all }
16
-
17
- it "should load the fixture data" do
18
- data = File.read(File.expand_path("../../data/dist/dmas.csv", __dir__))
19
- stub_request(:get, "#{USGeo.base_data_uri}/dmas.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
20
- USGeo::DesignatedMarketArea.load!
21
- expect(USGeo::DesignatedMarketArea.imported.count).to be > 200
22
- expect(USGeo::DesignatedMarketArea.removed.count).to eq 0
23
-
24
- dma = USGeo::DesignatedMarketArea.find("602")
25
- expect(dma.name).to eq "Chicago, IL"
26
- end
27
- end
28
-
29
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::Division do
4
-
5
- describe "associations" do
6
- it "should have a region" do
7
- division = USGeo::Division.new
8
- division.id = 1
9
- expect{ division.region }.to_not raise_error
10
- expect(division.build_region).to be_a(USGeo::Region)
11
- end
12
-
13
- it "should have states" do
14
- division = USGeo::Division.new
15
- division.id = 1
16
- expect{ division.states }.to_not raise_error
17
- expect(division.states.build).to be_a(USGeo::State)
18
- end
19
- end
20
-
21
- describe "load" do
22
- after { USGeo::Division.delete_all }
23
-
24
- it "should load the fixture data" do
25
- data = File.read(File.expand_path("../../data/dist/divisions.csv", __dir__))
26
- stub_request(:get, "#{USGeo.base_data_uri}/divisions.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
27
- USGeo::Division.load!
28
- expect(USGeo::Division.imported.count).to eq 9
29
- expect(USGeo::Division.removed.count).to eq 0
30
-
31
- division = USGeo::Division.find(2)
32
- expect(division.name).to eq "Middle Atlantic"
33
- expect(division.region_id).to eq 1
34
- end
35
- end
36
-
37
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::MetropolitanDivision do
4
-
5
- describe "associations" do
6
- it "should have a core_based_statistical_area" do
7
- division = USGeo::MetropolitanDivision.new
8
- division.geoid = "00001"
9
- expect{ division.core_based_statistical_area }.to_not raise_error
10
- expect(division.build_core_based_statistical_area).to be_a(USGeo::CoreBasedStatisticalArea)
11
- end
12
-
13
- it "should have counties" do
14
- division = USGeo::MetropolitanDivision.new
15
- division.geoid = "00001"
16
- expect{ division.counties }.to_not raise_error
17
- expect(division.counties.build).to be_a(USGeo::County)
18
- end
19
- end
20
-
21
- describe "load" do
22
- after { USGeo::MetropolitanDivision.delete_all }
23
-
24
- it "should load the fixture data" do
25
- data = File.read(File.expand_path("../../data/dist/metropolitan_divisions.csv", __dir__))
26
- stub_request(:get, "#{USGeo.base_data_uri}/metropolitan_divisions.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
27
- USGeo::MetropolitanDivision.load!
28
- expect(USGeo::MetropolitanDivision.imported.count).to be > 25
29
- expect(USGeo::MetropolitanDivision.removed.count).to eq 0
30
-
31
- division = USGeo::MetropolitanDivision.find("16984")
32
- expect(division.name).to eq "Chicago-Naperville-Evanston, IL"
33
- expect(division.cbsa_geoid).to eq "16980"
34
- expect(division.population).to be > 7_000_000
35
- expect(division.housing_units).to be > 2_000_000
36
- expect(division.land_area.round).to eq 3131
37
- expect(division.water_area.round).to eq 731
38
- end
39
- end
40
-
41
- end
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe USGeo::PlaceCounty do
4
-
5
- describe "associations" do
6
- it "should have a place" do
7
- place_county = USGeo::PlaceCounty.new
8
- place_county.place_geoid = "0000001"
9
- place_county.county_geoid = "00001"
10
- expect{ place_county.place }.to_not raise_error
11
- expect(place_county.build_place).to be_a(USGeo::Place)
12
- end
13
-
14
- it "should have a county" do
15
- place_county = USGeo::PlaceCounty.new
16
- place_county.place_geoid = "0000001"
17
- place_county.county_geoid = "00001"
18
- expect{ place_county.county }.to_not raise_error
19
- expect(place_county.build_county).to be_a(USGeo::County)
20
- end
21
- end
22
-
23
- describe "load" do
24
- after { USGeo::PlaceCounty.delete_all }
25
-
26
- it "should load the fixture data" do
27
- data = File.read(File.expand_path("../../data/dist/place_counties.csv", __dir__))
28
- stub_request(:get, "#{USGeo.base_data_uri}/place_counties.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
29
- USGeo::PlaceCounty.load!
30
- expect(USGeo::PlaceCounty.imported.count).to be > 30_000
31
- expect(USGeo::PlaceCounty.removed.count).to eq 0
32
-
33
- place_counties = USGeo::PlaceCounty.where(place_geoid: "3651000")
34
- expect(place_counties.size).to eq 5
35
- expect(place_counties.collect(&:county_geoid)).to match_array(["36005", "36047", "36061", "36081", "36085"])
36
- end
37
- end
38
-
39
- end
@@ -1,71 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe USGeo::Place do
4
-
5
- describe "associations" do
6
- it "should have a state" do
7
- place = USGeo::Place.new
8
- place.geoid = "0000001"
9
- expect{ place.state }.to_not raise_error
10
- expect(place.build_state).to be_a(USGeo::State)
11
- end
12
-
13
- it "should have a primary county" do
14
- place = USGeo::Place.new
15
- place.geoid = "0000001"
16
- expect{ place.primary_county }.to_not raise_error
17
- expect(place.build_primary_county).to be_a(USGeo::County)
18
- end
19
-
20
- it "should have an urban area" do
21
- place = USGeo::Place.new
22
- place.geoid = "0000001"
23
- expect{ place.urban_area }.to_not raise_error
24
- expect(place.build_urban_area).to be_a(USGeo::UrbanArea)
25
- end
26
-
27
- it "should have counties" do
28
- place = USGeo::Place.new
29
- place.geoid = "0000001"
30
- expect{ place.counties }.to_not raise_error
31
- expect{ place.place_counties }.to_not raise_error
32
- expect(place.place_counties.build).to be_a(USGeo::PlaceCounty)
33
- end
34
-
35
- it "should have zctas" do
36
- place = USGeo::Place.new
37
- place.geoid = "0000001"
38
- expect{ place.zctas }.to_not raise_error
39
- expect{ place.zcta_places }.to_not raise_error
40
- expect(place.zcta_places.build).to be_a(USGeo::ZctaPlace)
41
- end
42
- end
43
-
44
- describe "load" do
45
- after { USGeo::Place.delete_all }
46
-
47
- it "should load the fixture data" do
48
- data = File.read(File.expand_path("../../data/dist/places.csv", __dir__))
49
- stub_request(:get, "#{USGeo.base_data_uri}/places.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
50
- USGeo::Place.load!
51
- expect(USGeo::Place.imported.count).to be > 30_000
52
- expect(USGeo::Place.removed.count).to eq 0
53
-
54
- place = USGeo::Place.find("0649187")
55
- expect(place.gnis_id).to eq 2413013
56
- expect(place.name).to eq "Town of Moraga"
57
- expect(place.short_name).to eq "Moraga"
58
- expect(place.state_code).to eq "CA"
59
- expect(place.primary_county_geoid).to eq "06013"
60
- expect(place.urban_area_geoid).to eq "19504"
61
- expect(place.population).to be > 15_000
62
- expect(place.housing_units).to be > 5000
63
- expect(place.fips_class_code).to eq "C1"
64
- expect(place.land_area.round(1)).to eq 9.5
65
- expect(place.water_area.round(3)).to eq 0.009
66
- expect(place.lat.round).to eq 38
67
- expect(place.lng.round).to eq -122
68
- end
69
- end
70
-
71
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe USGeo::Region do
4
-
5
- describe "associations" do
6
- it "should have divisions" do
7
- region = USGeo::Region.new
8
- region.id = 1
9
- expect{ region.divisions }.to_not raise_error
10
- expect(region.divisions.build).to be_a(USGeo::Division)
11
- end
12
-
13
- it "should have states" do
14
- region = USGeo::Region.new
15
- region.id = 1
16
- expect{ region.states }.to_not raise_error
17
- expect(region.states.build).to be_a(USGeo::State)
18
- end
19
- end
20
-
21
- describe "load" do
22
- after { USGeo::Region.delete_all }
23
-
24
- it "should load the fixture data" do
25
- data = File.read(File.expand_path("../../data/dist/divisions.csv", __dir__))
26
- stub_request(:get, "#{USGeo.base_data_uri}/divisions.csv").to_return(body: data, headers: {"Content-Type": "text/csv; charset=UTF-8"})
27
- USGeo::Region.load!
28
- expect(USGeo::Region.imported.count).to eq 4
29
- expect(USGeo::Region.removed.count).to eq 0
30
-
31
- region = USGeo::Region.find(2)
32
- expect(region.name).to eq "Midwest"
33
- end
34
- end
35
-
36
- end