Class: LocalRealEstate::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/local_real_estate/scraper.rb

Overview

Each Indoc.css(‘.srp-item-body’)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zip) ⇒ Scraper

Returns a new instance of Scraper.



10
11
12
# File 'lib/local_real_estate/scraper.rb', line 10

def initialize(zip)
  @zip = zip
end

Instance Attribute Details

#zipObject

Returns the value of attribute zip.



8
9
10
# File 'lib/local_real_estate/scraper.rb', line 8

def zip
  @zip
end

Instance Method Details

#create_listingsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/local_real_estate/scraper.rb', line 22

def create_listings
  scrape_listings.each_with_index do |object, index|
    LocalRealEstate::Listing.new(
      address: object.css('.listing-street-address').text.strip,
      city: object.css('.listing-city').text,
      state: object.css('.listing-region').text,
      price: object.css('.srp-item-price').text.strip,
      bedrooms: object.css("ul li[data-label='property-meta-beds']").text,
      bathrooms: object.css("ul li[data-label='property-meta-baths']").text,
      sqft: object.css("ul li[data-label='property-meta-sqft']").text,
      cars: object.css("ul li[data-label='property-meta-garage']").text,
      lot_size: object.css("ul li[data-label='property-meta-lotsize']").text
    )
  end
end

#expand_listing(index) ⇒ Object



38
39
40
# File 'lib/local_real_estate/scraper.rb', line 38

def expand_listing(index)
  LocalRealEstate::Listing
end

#get_pageObject

this needs to be fixed. If zip starts with zero its lost with .to_i



14
15
16
# File 'lib/local_real_estate/scraper.rb', line 14

def get_page #this needs to be fixed. If zip starts with zero its lost with .to_i
  Nokogiri::HTML(open("https://www.realtor.com/realestateandhomes-search/#{@zip}"))
end

#scrape_listingsObject



18
19
20
# File 'lib/local_real_estate/scraper.rb', line 18

def scrape_listings
  self.get_page.css('.srp-item-body')
end