Class: Usatoday::Census::Housing

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

Constant Summary collapse

TEXT_FIELDS =
%w(place_name state_postal)
NUMERIC_FIELDS =
%w(fips gnis housing_units)
DECIMAL_FIELDS =
%w(pct_vacant)
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 = {}) ⇒ Housing

Returns a new instance of Housing.



13
14
15
16
17
# File 'lib/usatoday-census/housing.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/housing.rb', line 19

def self.init_from_api(params)
  housing = Housing.new(
  :place_name => text_field(params['Placename']),
  :state_postal => text_field(params['StatePostal']),
  :fips => integer_field(params['FIPS']),
  :gnis => integer_field(params['GNIS']),
  :pct_vacant => float_field(params['PctHisp']),
  :housing_units => integer_field(params['HousingUnits'])
  )
  housing
end

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



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

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