Class: Usatoday::Census::Ethnicity

Inherits:
Base
  • Object
show all
Defined in:
lib/usatoday-census/ethnicity.rb

Constant Summary collapse

TEXT_FIELDS =
%w(place_name state_postal)
NUMERIC_FIELDS =
%w(fips gnis)
DECIMAL_FIELDS =
%w(pct_hispanic pct_non_hispanic_white usat_diversity_index)
ALL_FIELDS =
TEXT_FIELDS + DECIMAL_FIELDS + NUMERIC_FIELDS

Constants inherited from Base

Base::API_BASE, Base::API_NAME, Base::API_SERVER

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, api_key=, build_request_url, float_field, integer_field, invoke, prepare_params, text_field

Constructor Details

#initialize(params = {}) ⇒ Ethnicity

Returns a new instance of Ethnicity.



13
14
15
16
17
# File 'lib/usatoday-census/ethnicity.rb', line 13

def initialize(params={})
	params.each_pair do |k,v|
		instance_variable_set("@#{k}", v)
	end
end

Class Method Details

.init_from_api(params) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/usatoday-census/ethnicity.rb', line 19

def self.init_from_api(params)
  ethnicity = Ethnicity.new(
  :place_name => text_field(params['Placename']),
  :state_postal => text_field(params['StatePostal']),
  :fips => integer_field(params['FIPS']),
  :gnis => integer_field(params['GNIS']),
  :pct_hispanic => float_field(params['PctHisp']),
  :pct_non_hispanic_white => float_field(params['PctNonHispWhite']),
  :usat_diversity_index => float_field(params['USATDiversityIndex'])
  )
end

.search(keypat, keyname = nil, sumlevid = 2) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/usatoday-census/ethnicity.rb', line 31

def self.search(keypat, keyname=nil, sumlevid=2)
  result = []
  params = prepare_params(keypat, keyname, sumlevid)
  			response = invoke('ethnicity', params)
  			response.each do |r|
	result << init_from_api(r)
end
result
end