Class: NewEugeneListingCli::Listing

Inherits:
Object
  • Object
show all
Defined in:
lib/new_eugene_listing_cli/listing.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address = nil, price = nil, bedrooms = nil, bathrooms = nil, url = nil) ⇒ Listing

Returns a new instance of Listing.



10
11
12
13
14
15
16
17
# File 'lib/new_eugene_listing_cli/listing.rb', line 10

def initialize(address = nil, price = nil, bedrooms = nil, bathrooms = nil, url = nil)
  @address = address
  @price = price
  @bedrooms = bedrooms
  @bathrooms = bathrooms
  @url = url
  @@all << self
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def address
  @address
end

#bathroomsObject

Returns the value of attribute bathrooms.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def bathrooms
  @bathrooms
end

#bedroomsObject

Returns the value of attribute bedrooms.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def bedrooms
  @bedrooms
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def price
  @price
end

#property_descriptionObject

Returns the value of attribute property_description.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def property_description
  @property_description
end

#property_typeObject

Returns the value of attribute property_type.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def property_type
  @property_type
end

#sq_feetObject

Returns the value of attribute sq_feet.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def sq_feet
  @sq_feet
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/new_eugene_listing_cli/listing.rb', line 2

def url
  @url
end

Class Method Details

.allObject



6
7
8
# File 'lib/new_eugene_listing_cli/listing.rb', line 6

def self.all
  @@all
end

.new_from_index_page(p) ⇒ Object



19
20
21
22
# File 'lib/new_eugene_listing_cli/listing.rb', line 19

def self.new_from_index_page(p)
  self.new(p.css(".addressDetail .h6").text.strip, p.css(".cardPrice").text.strip, p.css("[data-auto-test='beds']").text.gsub("bd", "").strip,
  p.css("[data-auto-test='baths']").text.gsub("ba", "").strip, "https://www.trulia.com" + p.css("a")[0]["href"].strip)
end

Instance Method Details

#docObject



36
37
38
# File 'lib/new_eugene_listing_cli/listing.rb', line 36

def doc
  @doc = Nokogiri::HTML(rpage = open(self.url, "User-Agent" => "User").read)
end