Class: CensusFor::County
- Inherits:
-
Object
- Object
- CensusFor::County
- Defined in:
- lib/census_for.rb
Class Method Summary collapse
- .coeff(county_state) ⇒ Object
- .highest_county_pop ⇒ Object
- .parse_county_state(county_state) ⇒ Object
- .population(request) ⇒ Object
- .population_lookup(parsed_county_state) ⇒ Object
Class Method Details
.coeff(county_state) ⇒ Object
91 92 93 94 |
# File 'lib/census_for.rb', line 91 def self.coeff(county_state) coefficient = (population(county_state) * 1000 / highest_county_pop).to_f coefficient < 1 ? 1 : coefficient end |
.highest_county_pop ⇒ Object
96 97 98 99 100 |
# File 'lib/census_for.rb', line 96 def self.highest_county_pop most_populous_county = CensusData.data.max_by { |x| x[:respop72014] } most_populous_county[:respop72014] #for 2014, this is Los Angeles County, CA: pop 10,116,705 end |
.parse_county_state(county_state) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/census_for.rb', line 57 def self.parse_county_state(county_state) transit = county_state.downcase.split(/[\s,]+/) - ["county"] - ["parish"] - ["borough"] - ["municipio"] - ["municipality"] if transit.size >= 3 city_state_key_array = [] 1.upto((transit.size - 1)) do |x| y = transit.size first = transit.take(x).join(' ') second = transit.last(y-x).join(' ') city_state_key_array << [first, second].flatten end else city_state_key_array = [transit] end city_state_key_array.each do |cs| county_name = cs.first state_name = cs.last state = Abbrev.converter(state_name) result = CensusData.data.find { |x| x[:"geo.display_label"] == "#{county_name.split.map(&:capitalize).join(' ')} County, #{state}" || x[:"geo.display_label"] == "#{county_name.split.map(&:capitalize).join(' ')} Parish, Louisiana" || x[:"geo.display_label"] == "#{county_name.split.map(&:capitalize).join(' ')} Municipio, Puerto Rico" } if result return result[:"geo.display_label"] end end return "not found" end |
.population(request) ⇒ Object
52 53 54 55 |
# File 'lib/census_for.rb', line 52 def self.population(request) parsed_request = parse_county_state(request) return population_lookup(parsed_request) end |
.population_lookup(parsed_county_state) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/census_for.rb', line 83 def self.population_lookup(parsed_county_state) if parsed_county_state == "not found" return "not found" else return CensusData.data.find { |x| x[:"geo.display_label"] == parsed_county_state }[:respop72014] end end |