Class: ZillowApi::People
- Inherits:
-
Object
- Object
- ZillowApi::People
- Defined in:
- lib/zillow_demographics/people.rb
Instance Attribute Summary collapse
-
#average_commute_time ⇒ Object
Returns the value of attribute average_commute_time.
-
#home_value ⇒ Object
Returns the value of attribute home_value.
-
#median_age ⇒ Object
Returns the value of attribute median_age.
-
#single_females ⇒ Object
Returns the value of attribute single_females.
-
#single_males ⇒ Object
Returns the value of attribute single_males.
-
#transportation ⇒ Object
Returns the value of attribute transportation.
-
#who_live_here ⇒ Object
Returns the value of attribute who_live_here.
Class Method Summary collapse
- .client ⇒ Object
- .demo_attributes(location, api_key) ⇒ Object
- .find_by_city(location, api_key) ⇒ Object
- .home_value(location, api_key) ⇒ Object
- .lives_here_attributes(location, api_key) ⇒ Object
- .mode_of_transit(location, api_key) ⇒ Object
- .parse_all(xml_package) ⇒ Object
- .parsed_response(location, api_key) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ People
constructor
A new instance of People.
Constructor Details
#initialize(attributes) ⇒ People
Returns a new instance of People.
8 9 10 11 12 13 14 15 16 |
# File 'lib/zillow_demographics/people.rb', line 8 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.who_live_here = attributes['lives here'] self.transportation = attributes['transportation'] self.home_value = attributes['zillow home value index'] end |
Instance Attribute Details
#average_commute_time ⇒ Object
Returns the value of attribute average_commute_time.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def average_commute_time @average_commute_time end |
#home_value ⇒ Object
Returns the value of attribute home_value.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def home_value @home_value end |
#median_age ⇒ Object
Returns the value of attribute median_age.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def median_age @median_age end |
#single_females ⇒ Object
Returns the value of attribute single_females.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def single_females @single_females end |
#single_males ⇒ Object
Returns the value of attribute single_males.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def single_males @single_males end |
#transportation ⇒ Object
Returns the value of attribute transportation.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def transportation @transportation end |
#who_live_here ⇒ Object
Returns the value of attribute who_live_here.
5 6 7 |
# File 'lib/zillow_demographics/people.rb', line 5 def who_live_here @who_live_here end |
Class Method Details
.client ⇒ Object
20 21 22 |
# File 'lib/zillow_demographics/people.rb', line 20 def client ZillowApi::Client.new end |
.demo_attributes(location, api_key) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/zillow_demographics/people.rb', line 24 def demo_attributes(location, 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("city").map { |values| values.child.text } if values == [] values = %w[N/A N/A N/A N/A N/A N/A N/A] end Hash[keys.zip(values)] end |
.find_by_city(location, api_key) ⇒ Object
62 63 64 65 |
# File 'lib/zillow_demographics/people.rb', line 62 def find_by_city(location, api_key) attributes = lives_here_attributes(location, api_key).merge(demo_attributes(location, api_key)).merge(home_value(location, api_key)).merge(mode_of_transit(location, api_key)) ZillowApi::People.new(attributes) end |
.home_value(location, api_key) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/zillow_demographics/people.rb', line 53 def home_value(location, 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("city").first.text if value == [] || value.to_i < 25000 value = ['N/A'] end { key => value } end |
.lives_here_attributes(location, api_key) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/zillow_demographics/people.rb', line 33 def lives_here_attributes(location, api_key) keys = parsed_response(location, api_key).search("page")[-1].search("liveshere").search("title").map { |value| value.text.downcase } values = parsed_response(location, api_key).search("page")[-1].search("liveshere").search("name").map { |key| key.text } if keys == [] { 'lives here' => 'N/A'} else { 'lives here' => Hash[keys.zip(values)] } end end |
.mode_of_transit(location, api_key) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/zillow_demographics/people.rb', line 43 def mode_of_transit(location, api_key) key = parsed_response(location, api_key).search("uniqueness").search("category").last.attributes['type'].value.downcase value = parsed_response(location, api_key).search("uniqueness").search("category").last.children.map {|s| s.text} if key != "transportation" { 'transportation' => ["N/A"] } else { key => value } end end |
.parse_all(xml_package) ⇒ Object
71 72 73 |
# File 'lib/zillow_demographics/people.rb', line 71 def parse_all(xml_package) Nokogiri::HTML(xml_package) end |
.parsed_response(location, api_key) ⇒ Object
67 68 69 |
# File 'lib/zillow_demographics/people.rb', line 67 def parsed_response(location, api_key) parse_all(client.get_city_data(location, api_key)) end |