Class: USGeo::State

Inherits:
BaseRecord
  • Object
show all
Includes:
Area, Population
Defined in:
lib/us_geo/state.rb

Overview

U.S. state or territory.

Constant Summary collapse

STATE_TYPE =
"state"
DISTRICT_TYPE =
"district"
TERRITORY_TYPE =
"territory"

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

#codeString

Returns 2-letter postal code of the state.

Returns:

  • (String)

    2-letter postal code of the state.



# File 'lib/us_geo/state.rb', line 27


#fipsString

Returns 2-digit FIPS code of the state.

Returns:

  • (String)

    2-digit FIPS code of the state.



# File 'lib/us_geo/state.rb', line 33


#nameString

Returns Name of the state.

Returns:

  • (String)

    Name of the state.



# File 'lib/us_geo/state.rb', line 30


#typeString

Returns Type of the state or territory.

Returns:

  • (String)

    Type of the state or territory.



# File 'lib/us_geo/state.rb', line 36


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
# File 'lib/us_geo/state.rb', line 44

def load!(uri = nil)
  location = data_uri(uri || "states.csv")

  import! do
    load_data_file(location) do |row|
      load_record!(code: row["Code"]) do |record|
        record.name = row["Name"]
        record.type = row["Type"]
        record.fips = row["FIPS"]
        record.region_id = row["Region ID"]
        record.division_id = row["Division ID"]
        record.population = row["Population"]
        record.housing_units = row["Housing Units"]
        record.land_area = row["Land Area"]
        record.water_area = row["Water Area"]
      end
    end
  end
end

Instance Method Details

#district?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/us_geo/state.rb', line 73

def district?
  type == DISTRICT_TYPE
end

#region(: region) ⇒ Region

Returns Region the state is in.

Returns:

  • (Region)

    Region the state is in.



41
# File 'lib/us_geo/state.rb', line 41

delegate :region, to: :division, allow_nil: true

#state?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/us_geo/state.rb', line 65

def state?
  type == STATE_TYPE
end

#territory?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/us_geo/state.rb', line 69

def territory?
  type == TERRITORY_TYPE
end