Class: USGeo::County

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

Attributes included from Area

#land_area, #water_area

Attributes included from Population

#housing_units, #population

Attributes inherited from BaseRecord

#status, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

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_codeString

Returns 2-character FIPS class code.

Returns:

  • (String)

    2-character FIPS class code.



# File 'lib/us_geo/county.rb', line 52


#geoidString

Returns 5-digit code for the county.

Returns:

  • (String)

    5-digit code for the county.



# File 'lib/us_geo/county.rb', line 40


#nameString

Returns Name of the county.

Returns:

  • (String)

    Name of the county.



# File 'lib/us_geo/county.rb', line 43


#short_nameString

Returns Short name of the county.

Returns:

  • (String)

    Short name of the county.



# File 'lib/us_geo/county.rb', line 46


#state_codeString

Returns 2-letter code for the state.

Returns:

  • (String)

    2-letter code for the state.



# File 'lib/us_geo/county.rb', line 49


#time_zone_2_nameString

Returns Time zone name.

Returns:

  • (String)

    Time zone name.



# File 'lib/us_geo/county.rb', line 58


#time_zone_nameString

Returns Time zone name.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    True if the county is a central county in the CBSA.



# File 'lib/us_geo/county.rb', line 61


#combined_statistical_areaUSGeo::CombinedStatisticalArea

Returns Combined statistical area that the county belongs to.

Returns:



66
# File 'lib/us_geo/county.rb', line 66

delegate :combined_statistical_area, to: :core_based_statistical_area, allow_nil: true

#county_fipsObject



108
109
110
# File 'lib/us_geo/county.rb', line 108

def county_fips
  geoid[2, 3]
end

#full_nameString

Full name of the county with the state.

Returns:

  • (String)


100
101
102
# File 'lib/us_geo/county.rb', line 100

def full_name
  "#{name}, #{state_code}"
end

#metropolitan_areaObject

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.

Returns:

  • (Boolean)


137
138
139
# File 'lib/us_geo/county.rb', line 137

def outlying?
  !central?
end

#state_fipsObject



104
105
106
# File 'lib/us_geo/county.rb', line 104

def state_fips
  geoid[0, 2]
end

#time_zoneActiveSupport::TimeZone?

Return a single time zone for the county. If the county has two time zones, only one is returned.

Returns:

  • (ActiveSupport::TimeZone, nil)


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_zonesArray<ActiveSupport::TimeZone>

Get all time zones for the county.

Returns:

  • (Array<ActiveSupport::TimeZone>)


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