us_geo 2.0.4 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6b963948f153ee9add87c2daa3d45fd79ec3ed1d79f156c94bec7cc8b9ca879
4
- data.tar.gz: 69b5d532013234f466319b8fc52ba4ea1809579bedc663f80258c7fd80246fef
3
+ metadata.gz: c76c059a8661033a5ac658fc7cb9aa3f3a10f478adb44c1c1c4681374dba1b78
4
+ data.tar.gz: fe0d4bc194e683493ed4bc7be6cb0f886b2223c7ae20e9b9c71595300cf4e5ee
5
5
  SHA512:
6
- metadata.gz: 51b285a6397f15652483f2c9f36eebbf423fa8ceb7b97fd672cb5361860e351333d562a6b36fb39388c21adb67ef4e7156ceaf1ccb88e727683fab5471ff8b1c
7
- data.tar.gz: d3ff6ae39376c494ac87f4533f6aeee5017546547f56ac1a1bb1cb35f8ad84cfac89f41090792c494de889d31718db6fff15cecbb13f8eb39ad5ee4823e0ae84
6
+ metadata.gz: a11dc0cebe135efdec9b1d6a94ebfc87786311ef2266cd987778121de1b18ead07d099914342ba027d0002ff574d4d9f7c39f226c412a3c02c97dc51f9f05fc6
7
+ data.tar.gz: d23e1c89a23594ee86284f3597a22e0f26f69621b827dc411abad38088aa8faf1b0dace47d619950bc0e5714f75df80034aeb27cec58a41f8960821f14455926
data/CHANGELOG.md CHANGED
@@ -4,13 +4,34 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.1.1
8
+
9
+ ### Fixed
10
+
11
+ - Made `belongs_to` associations on models optional so that you don't need to import the full data set in order to have valid records.
12
+
13
+ ## 2.1.0
14
+
15
+ ### Changed
16
+
17
+ - Lazy load ActiveRecord classes so they don't add overhead during application initialization.
18
+ - Update distribution data files with latest Census data as of March 2024.
19
+ - Geographic data is based on 2023 Gazetteer files.
20
+ - Population and housing data are based on 2022 ACS estimates.
21
+ - Some of the Core Based Statistical Area, Combined Statisical Area, and Metropolitan Division names have changed.
22
+ - All Urban Areas now include "Urban Area" in their name. The Census Bureau no longer distinguishes between Urbanized Areas and Urban Clusters and the data now reflects the official names.
23
+
24
+ ### Deprecated
25
+
26
+ - The USGeo::UrbanizedArea and USGeo::UrbanCluster classes are deprecated. These classes are now just aliases for USGeo::UrbanArea. You can still use the `urbanized?` and `cluster?` methods to determine the size of an UrbanArea based on the pre-2020 definition of greater or less then 50,000 residents.
27
+
7
28
  ## 2.0.4
8
29
 
30
+ ### Fixed
31
+
9
32
  - Remove "Urbanized Area" from short name for urban areas.
10
33
  - Fix short name for Louisville, KY in the in the CBSA's, CSA's, and Urban Areas to omit "Jefferson County" so it matches convention for other short names of only showing the major city.
11
34
 
12
-
13
-
14
35
  ## 2.0.3
15
36
 
16
37
  ### Added
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # USGeo
2
2
 
3
- [![Build Status](https://travis-ci.com/bdurand/us_geo.svg?branch=master)](https://travis-ci.com/bdurand/us_geo)
3
+ [![Continuous Integration](https://github.com/bdurand/us_geo/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/us_geo/actions/workflows/continuous_integration.yml)
4
4
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
5
+ [![Gem Version](https://badge.fury.io/rb/us_geo.svg)](https://badge.fury.io/rb/us_geo)
5
6
 
6
7
  This gem provides a variety of U.S. geographic data ActiveRecord models. It is designed to provide a normalized way to access the data from a relational database. This is by no means a complete set of data.
7
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.4
1
+ 2.1.1
@@ -5,13 +5,10 @@ class UrbanAreasController < ApplicationController
5
5
  urban_areas = USGeo::UrbanArea.not_removed
6
6
 
7
7
  @tab = params[:tab]
8
- if @tab.present?
9
- type = if @tab == "urbanized"
10
- "UrbanizedArea"
11
- elsif @tab == "cluster"
12
- "UrbanCluster"
13
- end
14
- urban_areas = urban_areas.where(type: type)
8
+ if @tab == "urbanized"
9
+ urban_areas = urban_areas.where(population: 50_000..)
10
+ elsif @tab == "cluster"
11
+ urban_areas = urban_areas.where(population: ...50_000)
15
12
  end
16
13
 
17
14
  @urban_areas = urban_areas.order(:name)
data/lib/us_geo/county.rb CHANGED
@@ -12,7 +12,7 @@ module USGeo
12
12
 
13
13
  belongs_to :core_based_statistical_area, foreign_key: :cbsa_geoid, optional: true, inverse_of: :counties
14
14
  belongs_to :metropolitan_division, foreign_key: :metropolitan_division_geoid, optional: true, inverse_of: :counties
15
- belongs_to :state, foreign_key: :state_code, inverse_of: :counties
15
+ belongs_to :state, foreign_key: :state_code, optional: true, inverse_of: :counties
16
16
 
17
17
  has_many :subdivisions, -> { not_removed }, foreign_key: :county_geoid, inverse_of: :county, class_name: "USGeo::CountySubdivision"
18
18
 
@@ -8,7 +8,7 @@ module USGeo
8
8
 
9
9
  self.primary_key = "geoid"
10
10
 
11
- belongs_to :county, foreign_key: :county_geoid, inverse_of: :subdivisions
11
+ belongs_to :county, foreign_key: :county_geoid, optional: true, inverse_of: :subdivisions
12
12
 
13
13
  has_many :zcta_county_subdivisions, -> { not_removed }, foreign_key: :county_subdivision_geoid, inverse_of: :county_subdivision, dependent: :destroy
14
14
  has_many :zctas, -> { not_removed }, through: :zcta_county_subdivisions
@@ -6,7 +6,7 @@ module USGeo
6
6
  include Population
7
7
  include Area
8
8
 
9
- belongs_to :region, inverse_of: :divisions
9
+ belongs_to :region, optional: true, inverse_of: :divisions
10
10
  has_many :states, -> { not_removed }, inverse_of: :division
11
11
 
12
12
  validates :name, presence: true, length: {maximum: 30}, uniqueness: true
data/lib/us_geo/place.rb CHANGED
@@ -26,7 +26,7 @@ module USGeo
26
26
 
27
27
  # !@method primary_county
28
28
  # @return [County] County that contains most of the place.
29
- belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
29
+ belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
30
30
 
31
31
  # !@method urban_area
32
32
  # @return [UrbanArea] Urban area that the place is a part of.
@@ -34,7 +34,7 @@ module USGeo
34
34
 
35
35
  # !@method state
36
36
  # @return [State] State that the place is in.
37
- belongs_to :state, foreign_key: :state_code, inverse_of: :places
37
+ belongs_to :state, foreign_key: :state_code, optional: true, inverse_of: :places
38
38
 
39
39
  validates :geoid, length: {is: 7}
40
40
  validates :state_code, length: {is: 2}
data/lib/us_geo/state.rb CHANGED
@@ -13,8 +13,8 @@ module USGeo
13
13
  self.primary_key = "code"
14
14
  self.inheritance_column = :_type_disabled
15
15
 
16
- belongs_to :region, optional: -> { territory? }, inverse_of: :states
17
- belongs_to :division, optional: -> { territory? }, inverse_of: :states
16
+ belongs_to :region, optional: true, inverse_of: :states
17
+ belongs_to :division, optional: true, inverse_of: :states
18
18
 
19
19
  has_many :counties, -> { not_removed }, foreign_key: :state_code, inverse_of: :state
20
20
  has_many :places, -> { not_removed }, foreign_key: :state_code, inverse_of: :state
@@ -19,7 +19,7 @@ module USGeo
19
19
 
20
20
  # !@method primary_county
21
21
  # @return [USGeo::County] Primary county that contains most of the urban area.
22
- belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
22
+ belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
23
23
 
24
24
  # !@method urban_area_county_subdivisions
25
25
  # @return [ActiveRecord::Relation<USGeo::UrbanAreaCountySubdivision>] County subdivision to urban area mapping.
@@ -85,12 +85,18 @@ module USGeo
85
85
  end
86
86
  end
87
87
 
88
+ # Return true if the population is greater than or equal to 50,000.
89
+ #
90
+ # @return [Boolean]
88
91
  def urbanized?
89
- raise NotImplementedError
92
+ population >= 50_000
90
93
  end
91
94
 
95
+ # Return true if the population is less than 50,000.
96
+ #
97
+ # @return [Boolean]
92
98
  def cluster?
93
- raise NotImplementedError
99
+ population < 50_000
94
100
  end
95
101
  end
96
102
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module USGeo
4
4
  # Urban area with population < 50,000.
5
+ #
6
+ # @deprecated This class will be removed in version 3.0 and only UrbanArea will be used.
5
7
  class UrbanCluster < UrbanArea
6
8
  def urbanized?
7
9
  false
@@ -2,6 +2,8 @@
2
2
 
3
3
  module USGeo
4
4
  # Urban area with population >= 50,000.
5
+ #
6
+ # @deprecated This class will be removed in version 3.0 and only UrbanArea will be used.
5
7
  class UrbanizedArea < UrbanArea
6
8
  def urbanized?
7
9
  true
data/lib/us_geo/zcta.rb CHANGED
@@ -36,7 +36,7 @@ module USGeo
36
36
 
37
37
  # @!method primary_county
38
38
  # @return [USGeo::County] County that contains most of the ZCTA's land area.
39
- belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
39
+ belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
40
40
 
41
41
  # @!method zcta_urban_areas
42
42
  # @return [ActiveRecord::Relation] ZCTA to urban area mappings.
@@ -48,7 +48,7 @@ module USGeo
48
48
 
49
49
  # @!method primary_urban_area
50
50
  # @return [USGeo::UrbanArea] Urban area that contains most of the ZCTA's land area.
51
- belongs_to :primary_urban_area, foreign_key: :primary_urban_area_geoid, class_name: "USGeo::UrbanArea"
51
+ belongs_to :primary_urban_area, foreign_key: :primary_urban_area_geoid, optional: true, class_name: "USGeo::UrbanArea"
52
52
 
53
53
  # @!method zcta_county_subdivisions
54
54
  # @return [ActiveRecord::Relation] ZCTA to county subdivision mappings.
@@ -60,7 +60,7 @@ module USGeo
60
60
 
61
61
  # @!method primary_county_subdivision
62
62
  # @return [USGeo::CountySubdivision] County subdivision that contains most of the ZCTA's land area.
63
- belongs_to :primary_county_subdivision, foreign_key: :primary_county_subdivision_geoid, class_name: "USGeo::CountySubdivision"
63
+ belongs_to :primary_county_subdivision, foreign_key: :primary_county_subdivision_geoid, optional: true, class_name: "USGeo::CountySubdivision"
64
64
 
65
65
  # @!method zcta_places
66
66
  # @return [ActiveRecord::Relation] ZCTA to place mappings.
@@ -72,7 +72,7 @@ module USGeo
72
72
 
73
73
  # @!method primary_place
74
74
  # @return [USGeo::Place] Place that contains most of the ZCTA's land area.
75
- belongs_to :primary_place, foreign_key: :primary_place_geoid, class_name: "USGeo::Place"
75
+ belongs_to :primary_place, foreign_key: :primary_place_geoid, optional: true, class_name: "USGeo::Place"
76
76
 
77
77
  # @!method zcta_mappings
78
78
  # @return [ActiveRecord::Relation] 2010 ZCTA to current ZCTA mappings.
data/lib/us_geo.rb CHANGED
@@ -4,37 +4,37 @@ require "active_record"
4
4
 
5
5
  require_relative "us_geo/version"
6
6
 
7
- require_relative "us_geo/area"
8
- require_relative "us_geo/population"
9
- require_relative "us_geo/base_record"
10
-
11
- require_relative "us_geo/region"
12
- require_relative "us_geo/division"
13
- require_relative "us_geo/state"
14
- require_relative "us_geo/combined_statistical_area"
15
- require_relative "us_geo/core_based_statistical_area"
16
- require_relative "us_geo/metropolitan_area"
17
- require_relative "us_geo/micropolitan_area"
18
- require_relative "us_geo/metropolitan_division"
19
- require_relative "us_geo/county"
20
- require_relative "us_geo/county_subdivision"
21
- require_relative "us_geo/place"
22
- require_relative "us_geo/place_county"
23
- require_relative "us_geo/urban_area"
24
- require_relative "us_geo/urban_area_county"
25
- require_relative "us_geo/urban_area_county_subdivision"
26
- require_relative "us_geo/urban_cluster"
27
- require_relative "us_geo/urbanized_area"
28
- require_relative "us_geo/zcta"
29
- require_relative "us_geo/zcta_county"
30
- require_relative "us_geo/zcta_county_subdivision"
31
- require_relative "us_geo/zcta_mapping"
32
- require_relative "us_geo/zcta_place"
33
- require_relative "us_geo/zcta_urban_area"
34
-
35
7
  require_relative "us_geo/engine" if defined?(::Rails::Engine)
36
8
 
37
9
  module USGeo
10
+ autoload :Area, "us_geo/area"
11
+ autoload :Population, "us_geo/population"
12
+ autoload :BaseRecord, "us_geo/base_record"
13
+
14
+ autoload :Region, "us_geo/region"
15
+ autoload :Division, "us_geo/division"
16
+ autoload :State, "us_geo/state"
17
+ autoload :CombinedStatisticalArea, "us_geo/combined_statistical_area"
18
+ autoload :CoreBasedStatisticalArea, "us_geo/core_based_statistical_area"
19
+ autoload :MetropolitanArea, "us_geo/metropolitan_area"
20
+ autoload :MicropolitanArea, "us_geo/micropolitan_area"
21
+ autoload :MetropolitanDivision, "us_geo/metropolitan_division"
22
+ autoload :County, "us_geo/county"
23
+ autoload :CountySubdivision, "us_geo/county_subdivision"
24
+ autoload :Place, "us_geo/place"
25
+ autoload :PlaceCounty, "us_geo/place_county"
26
+ autoload :UrbanArea, "us_geo/urban_area"
27
+ autoload :UrbanAreaCounty, "us_geo/urban_area_county"
28
+ autoload :UrbanAreaCountySubdivision, "us_geo/urban_area_county_subdivision"
29
+ autoload :UrbanCluster, "us_geo/urban_cluster"
30
+ autoload :UrbanizedArea, "us_geo/urbanized_area"
31
+ autoload :Zcta, "us_geo/zcta"
32
+ autoload :ZctaCounty, "us_geo/zcta_county"
33
+ autoload :ZctaCountySubdivision, "us_geo/zcta_county_subdivision"
34
+ autoload :ZctaMapping, "us_geo/zcta_mapping"
35
+ autoload :ZctaPlace, "us_geo/zcta_place"
36
+ autoload :ZctaUrbanArea, "us_geo/zcta_urban_area"
37
+
38
38
  BASE_DATA_URI = "https://raw.githubusercontent.com/bdurand/us_geo/master/data/2020_dist"
39
39
 
40
40
  class << self
data/us_geo.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "activerecord", ">= 5.2"
32
+ spec.add_dependency "csv"
32
33
 
33
34
  spec.add_development_dependency "bundler"
34
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: us_geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-20 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: csv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -219,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
233
  - !ruby/object:Gem::Version
220
234
  version: '0'
221
235
  requirements: []
222
- rubygems_version: 3.4.12
236
+ rubygems_version: 3.4.10
223
237
  signing_key:
224
238
  specification_version: 4
225
239
  summary: Collection of geographic data for the United States for use with ActiveRecord