Class: Usatoday::Census::Race
Constant Summary collapse
- TEXT_FIELDS =
%w(place_name state_postal)
- NUMERIC_FIELDS =
%w(fips gnis)
- DECIMAL_FIELDS =
%w(pct_white pct_black pct_american_indian pct_asian pct_native_hawaiian pct_two_or_more)
- 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
-
#initialize(params = {}) ⇒ Race
constructor
A new instance of Race.
Methods inherited from Base
api_key, api_key=, build_request_url, float_field, integer_field, invoke, prepare_params, text_field
Constructor Details
#initialize(params = {}) ⇒ Race
Returns a new instance of Race.
13 14 15 16 17 |
# File 'lib/usatoday-census/race.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 30 31 32 33 |
# File 'lib/usatoday-census/race.rb', line 19 def self.init_from_api(params) race = Race.new( :place_name => text_field(params['Placename']), :state_postal => text_field(params['StatePostal']), :fips => integer_field(params['FIPS']), :gnis => integer_field(params['GNIS']), :pct_white => float_field(params['PctWhite']), :pct_black => float_field(params['PctBlack']), :pct_american_indian => float_field(params['PctAmInd']), :pct_asian => float_field(params['PctAsian']), :pct_native_hawaiian => float_field(params['PctNatHawOth']), :pct_two_or_more => float_field(params['PctTwoOrMore']) ) race end |
.search(keypat, keyname = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/usatoday-census/race.rb', line 35 def self.search(keypat, keyname=nil) result = [] params = prepare_params(keypat, keyname) response = invoke('race', params) response.each do |r| result << init_from_api(r) end result end |