class DailyProperties::Property

Attributes

address[RW]
price[RW]
sold_date[RW]
url[RW]

Public Class Methods

clear_all() click to toggle source
# File lib/daily_properties/property.rb, line 26
def self.clear_all
    @@all.clear
end
find(index) click to toggle source
# File lib/daily_properties/property.rb, line 30
def self.find(index)
    index < 0 ? nil : @@all[index]
end
new(address = nil, price = nil, sold_date = nil, url = nil) click to toggle source
# File lib/daily_properties/property.rb, line 5
def initialize(address = nil, price = nil, sold_date = nil, url = nil)
    @address = address 
    @price = price
    @sold_date = sold_date
    @url = url
    @@all << self unless @@all.detect{|p| p.address == address}
end
new_from_page(property) click to toggle source
# File lib/daily_properties/property.rb, line 13
def self.new_from_page(property)
    self.new(
        property.css(".zsg-photo-card-address").text,
        property.css("span.zsg-photo-card-status").text,
        property.css(".zsg-photo-card-notification").text,
        'http://www.zillow.com' + property.css("a").attr("href")
        )
end
properties() click to toggle source
# File lib/daily_properties/property.rb, line 22
def self.properties
    @@all 
end
sort_by_price() click to toggle source
# File lib/daily_properties/property.rb, line 42
def self.sort_by_price
    @@all.sort! {|a, b| b.convert_price_to_int <=> a.convert_price_to_int}
end

Public Instance Methods

convert_price_to_int() click to toggle source
# File lib/daily_properties/property.rb, line 34
def convert_price_to_int
    if price.include?("M")
        (price.split("$")[1].gsub("M", "").to_f*1000000).to_i
    else
        price.split("$")[1].gsub(",", "").to_i 
    end
end