Class: USGeo::County

Inherits:
BaseRecord
  • Object
show all
Includes:
Demographics
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Demographics

#percent_land, #population_density, #total_area

Methods inherited from BaseRecord

#imported?, #manual?, #removed?

Class Method Details

.load!(uri = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/us_geo/county.rb', line 44

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.dma_code = row["DMA"]
        record.time_zone_name = row["Time Zone"]
        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 = area_meters_to_miles(row["Land Area"])
        record.water_area = area_meters_to_miles(row["Water Area"])
        record.lat = row["Latitude"]
        record.lng = row["Longitude"]
      end
    end
  end
end

Instance Method Details

#county_fipsObject



75
76
77
# File 'lib/us_geo/county.rb', line 75

def county_fips
  geoid[2, 3]
end

#metropolitan_areaObject

Return the CBSA only if it is a metropolitan area.



80
81
82
# File 'lib/us_geo/county.rb', line 80

def metropolitan_area
  core_based_statistical_area if core_based_statistical_area && core_based_statistical_area.metropolitan?
end

#state_fipsObject



71
72
73
# File 'lib/us_geo/county.rb', line 71

def state_fips
  geoid[0, 2]
end

#time_zoneObject



84
85
86
# File 'lib/us_geo/county.rb', line 84

def time_zone
  ActiveSupport::TimeZone[time_zone_name] if time_zone_name
end