Class: USGeo::County
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- USGeo::County
- Includes:
- Area, Population
- Defined in:
- lib/us_geo/county.rb
Overview
County or county equivalent. Counties are composed of zero or more ZCTA’s and may belong to a CBSA. The county’s significance withing the CBSA is indicated by the central flag which indicates if it is a central or outlying county.
Constant Summary
Constants inherited from BaseRecord
BaseRecord::STATUS_IMPORTED, BaseRecord::STATUS_MANUAL, BaseRecord::STATUS_REMOVED
Instance Attribute Summary collapse
-
#fips_class_code ⇒ String
2-character FIPS class code.
-
#geoid ⇒ String
5-digit code for the county.
-
#name ⇒ String
Name of the county.
-
#short_name ⇒ String
Short name of the county.
-
#state_code ⇒ String
2-letter code for the state.
-
#time_zone_2_name ⇒ String
Time zone name.
-
#time_zone_name ⇒ String
Time zone name.
Attributes included from Area
Attributes included from Population
Attributes inherited from BaseRecord
Class Method Summary collapse
Instance Method Summary collapse
-
#central? ⇒ Boolean
True if the county is a central county in the CBSA.
-
#combined_statistical_area ⇒ USGeo::CombinedStatisticalArea
Combined statistical area that the county belongs to.
- #county_fips ⇒ Object
-
#full_name ⇒ String
Full name of the county with the state.
-
#metropolitan_area ⇒ Object
Return the CBSA only if it is a metropolitan area.
-
#outlying? ⇒ Boolean
True if the county is an outlying county in the CBSA.
- #state_fips ⇒ Object
-
#time_zone ⇒ ActiveSupport::TimeZone?
Return a single time zone for the county.
-
#time_zones ⇒ Array<ActiveSupport::TimeZone>
Get all time zones for the county.
Methods included from Area
#land_area_km, #percent_land, #total_area, #water_area_km
Methods included from Population
#housing_density, #housing_density_km, #population_density, #population_density_km
Methods inherited from BaseRecord
#imported?, #manual?, #removed?
Instance Attribute Details
#fips_class_code ⇒ String
Returns 2-character FIPS class code.
|
|
# File 'lib/us_geo/county.rb', line 52
|
#geoid ⇒ String
Returns 5-digit code for the county.
|
|
# File 'lib/us_geo/county.rb', line 40
|
#name ⇒ String
Returns Name of the county.
|
|
# File 'lib/us_geo/county.rb', line 43
|
#short_name ⇒ String
Returns Short name of the county.
|
|
# File 'lib/us_geo/county.rb', line 46
|
#state_code ⇒ String
Returns 2-letter code for the state.
|
|
# File 'lib/us_geo/county.rb', line 49
|
#time_zone_2_name ⇒ String
Returns Time zone name.
|
|
# File 'lib/us_geo/county.rb', line 58
|
#time_zone_name ⇒ String
Returns Time zone name.
|
|
# File 'lib/us_geo/county.rb', line 55
|
Class Method Details
.load!(uri = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/us_geo/county.rb', line 69 def load!(uri = nil) location = data_uri(uri || "counties.csv") import! do load_data_file(location) do |row| load_record!(geoid: row["GEOID"]) do |record| record.gnis_id = row["GNIS ID"] record.name = row["Name"] record.short_name = row["Short Name"] record.state_code = row["State"] record.cbsa_geoid = row["CBSA"] record.metropolitan_division_geoid = row["Metropolitan Division"] record.time_zone_name = row["Time Zone"] record.time_zone_2_name = row["Time Zone 2"] record.fips_class_code = row["FIPS Class"] record.central = (row["Central"] == "T") record.population = row["Population"] record.housing_units = row["Housing Units"] record.land_area = row["Land Area"] record.water_area = row["Water Area"] record.lat = row["Latitude"] record.lng = row["Longitude"] end end end end |
Instance Method Details
#central? ⇒ Boolean
Returns True if the county is a central county in the CBSA.
|
|
# File 'lib/us_geo/county.rb', line 61
|
#combined_statistical_area ⇒ USGeo::CombinedStatisticalArea
Returns Combined statistical area that the county belongs to.
66 |
# File 'lib/us_geo/county.rb', line 66 delegate :combined_statistical_area, to: :core_based_statistical_area, allow_nil: true |
#county_fips ⇒ Object
108 109 110 |
# File 'lib/us_geo/county.rb', line 108 def county_fips geoid[2, 3] end |
#full_name ⇒ String
Full name of the county with the state.
100 101 102 |
# File 'lib/us_geo/county.rb', line 100 def full_name "#{name}, #{state_code}" end |
#metropolitan_area ⇒ Object
Return the CBSA only if it is a metropolitan area.
113 114 115 |
# File 'lib/us_geo/county.rb', line 113 def metropolitan_area core_based_statistical_area if core_based_statistical_area&.metropolitan? end |
#outlying? ⇒ Boolean
True if the county is an outlying county in the CBSA.
137 138 139 |
# File 'lib/us_geo/county.rb', line 137 def !central? end |
#state_fips ⇒ Object
104 105 106 |
# File 'lib/us_geo/county.rb', line 104 def state_fips geoid[0, 2] end |
#time_zone ⇒ ActiveSupport::TimeZone?
Return a single time zone for the county. If the county has two time zones, only one is returned.
121 122 123 |
# File 'lib/us_geo/county.rb', line 121 def time_zone ActiveSupport::TimeZone[time_zone_name] if time_zone_name end |
#time_zones ⇒ Array<ActiveSupport::TimeZone>
Get all time zones for the county.
128 129 130 131 132 |
# File 'lib/us_geo/county.rb', line 128 def time_zones [time_zone_name, time_zone_2_name].compact.collect do |tz_name| ActiveSupport::TimeZone[tz_name] end.compact end |