Class: Blockers::Blocker

Inherits:
Object
  • Object
show all
Defined in:
lib/blockers/blocker.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, price) ⇒ Blocker

Returns a new instance of Blocker.



15
16
17
18
19
20
# File 'lib/blockers/blocker.rb', line 15

def initialize(name, url, price)
  @name = name
  @url = url
  @price = price
  @@all << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/blockers/blocker.rb', line 3

def name
  @name
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/blockers/blocker.rb', line 3

def price
  @price
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/blockers/blocker.rb', line 3

def url
  @url
end

Class Method Details

.allObject



7
8
9
# File 'lib/blockers/blocker.rb', line 7

def self.all
  @@all
end

.deleteObject



11
12
13
# File 'lib/blockers/blocker.rb', line 11

def self.delete
  @@all.clear
end

.find(index) ⇒ Object



22
23
24
# File 'lib/blockers/blocker.rb', line 22

def self.find(index)
  self.all[index]
end

.scrapeObject



30
31
32
33
34
35
36
37
38
# File 'lib/blockers/blocker.rb', line 30

def self.scrape
  doc = Nokogiri::HTML(open('http://www.goaliemonkey.com/equipment/blockers/sr-goalie-blockers/sort-by/price/sort-direction/asc.html'))
  doc.css("li.item.span3").each do |item|
    name = item.css("div.caption h2.product-name a").text.gsub("Goalie Blocker", "")
    url = item.css("div.caption h2.product-name a").attribute("href").value
    price = item.css("div.price-box p.regular-price span.regular-price span.price").text
    self.new(name, url, price)
  end
end