Class: DailyProperties::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/daily_properties/property.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address = nil, price = nil, sold_date = nil, url = nil) ⇒ Property

Returns a new instance of Property.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



2
3
4
# File 'lib/daily_properties/property.rb', line 2

def address
  @address
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/daily_properties/property.rb', line 2

def price
  @price
end

#sold_dateObject

Returns the value of attribute sold_date.



2
3
4
# File 'lib/daily_properties/property.rb', line 2

def sold_date
  @sold_date
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/daily_properties/property.rb', line 2

def url
  @url
end

Class Method Details

.clear_allObject



26
27
28
# File 'lib/daily_properties/property.rb', line 26

def self.clear_all
    @@all.clear
end

.find(index) ⇒ Object



30
31
32
# File 'lib/daily_properties/property.rb', line 30

def self.find(index)
    index < 0 ? nil : @@all[index]
end

.new_from_page(property) ⇒ Object



13
14
15
16
17
18
19
20
# 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

.propertiesObject



22
23
24
# File 'lib/daily_properties/property.rb', line 22

def self.properties
    @@all 
end

.sort_by_priceObject



42
43
44
# 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

Instance Method Details

#convert_price_to_intObject



34
35
36
37
38
39
40
# 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