Class: CensusFor::State

Inherits:
Object
  • Object
show all
Defined in:
lib/census_for.rb

Class Method Summary collapse

Class Method Details

.population(request) ⇒ Object



119
120
121
122
# File 'lib/census_for.rb', line 119

def self.population(request)
  state = Abbrev.converter(request)
  return population_lookup(state)
end

.population_lookup(state) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/census_for.rb', line 124

def self.population_lookup(state)
  if state
    counties_in_state = []

    CensusData.data.each do |x|
      counties_in_state << x if x[:"geo.display_label"].split(/\s*,\s*/).last == "#{state}"
    end

    counties_pop_total = 0
    counties_in_state.each do |c|
      counties_pop_total += c[:respop72014]
    end
    return counties_pop_total
  else
    return 'not found'
  end
end