Class: ZillowApi::National

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ National

Returns a new instance of National.



7
8
9
10
11
12
13
# File 'lib/zillow_demographics/national.rb', line 7

def initialize(attributes)
  self.average_commute_time = attributes['average commute time (minutes)']
  self.single_females       = attributes['single females']
  self.single_males         = attributes['single males']
  self.median_age           = attributes['median age']
  self.home_value           = attributes['zillow home value index']
end

Instance Attribute Details

#average_commute_timeObject

Returns the value of attribute average_commute_time.



5
6
7
# File 'lib/zillow_demographics/national.rb', line 5

def average_commute_time
  @average_commute_time
end

#home_valueObject

Returns the value of attribute home_value.



5
6
7
# File 'lib/zillow_demographics/national.rb', line 5

def home_value
  @home_value
end

#median_ageObject

Returns the value of attribute median_age.



5
6
7
# File 'lib/zillow_demographics/national.rb', line 5

def median_age
  @median_age
end

#single_femalesObject

Returns the value of attribute single_females.



5
6
7
# File 'lib/zillow_demographics/national.rb', line 5

def single_females
  @single_females
end

#single_malesObject

Returns the value of attribute single_males.



5
6
7
# File 'lib/zillow_demographics/national.rb', line 5

def single_males
  @single_males
end

Class Method Details

.clientObject



17
18
19
# File 'lib/zillow_demographics/national.rb', line 17

def client
  ZillowApi::Client.new
end

.demo_attributes(location = 'chicago', api_key) ⇒ Object



21
22
23
24
25
# File 'lib/zillow_demographics/national.rb', line 21

def demo_attributes(location='chicago', api_key)
  keys = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").map {|key| key.child.text.downcase }
  values = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").search("nation").map { |values| values.child.text }
  Hash[keys.zip(values)]
end

.find(location = 'chicago', api_key) ⇒ Object



33
34
35
36
# File 'lib/zillow_demographics/national.rb', line 33

def find(location='chicago', api_key)
  attributes = demo_attributes(location, api_key).merge(home_value(location, api_key))
  ZillowApi::National.new(attributes)
end

.home_value(location = 'chicago', api_key) ⇒ Object



27
28
29
30
31
# File 'lib/zillow_demographics/national.rb', line 27

def home_value(location='chicago', api_key)
  key = parsed_response(location, api_key).search("page").first.search("data").first.search("attribute").first.child.text.downcase
  value = parsed_response(location, api_key).search("page").first.search("data").first.search("nation").first.text
  { key => value }
end

.parse_all(xml_package) ⇒ Object



42
43
44
# File 'lib/zillow_demographics/national.rb', line 42

def parse_all(xml_package)
  Nokogiri::HTML(xml_package)
end

.parsed_response(location = 'chicago', api_key) ⇒ Object



38
39
40
# File 'lib/zillow_demographics/national.rb', line 38

def parsed_response(location='chicago', api_key)
  parse_all(client.get_city_data(location, api_key))
end