Class: AptFinder::Listings

Inherits:
Object
  • Object
show all
Defined in:
lib/apt_finder/listings.rb

Constant Summary collapse

@@listings =
[]

Class Method Summary collapse

Class Method Details

.allObject



19
20
21
# File 'lib/apt_finder/listings.rb', line 19

def self.all
  @@listings
end

.listingsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/apt_finder/listings.rb', line 5

def self.listings
  doc = Nokogiri::HTML(open("http://www.apartmentfinder.com/New-York/New-York-Apartments"))

  doc.css('div.listingContent')[0..9].each_with_index do |list, index|
    title = list.css('div.listingTitle').text.strip
    price = list.css('span.altRentDisplay').text.strip
    link = list.css('div.listingTitle a').attr('href').value

    puts "#{index + 1}. #{title} - price range from #{price}"
    self.all << [title, price, link]
  end
  self.all
end