Class: CensusFor::State

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

Class Method Summary collapse

Class Method Details

.population(request) ⇒ Object



126
127
128
129
# File 'lib/census_for.rb', line 126

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

.population_lookup(state) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/census_for.rb', line 131

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