Class: Knitpickr::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/knitpickr/scraper.rb

Constant Summary collapse

@@all_names =
[]
@@all_fibers =
[]
@@all_weights =
[]
@@all_yarns =
[]
@@all_sale =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#docObject

Returns the value of attribute doc.



5
6
7
# File 'lib/knitpickr/scraper.rb', line 5

def doc
  @doc
end

#yarnObject

Returns the value of attribute yarn.



5
6
7
# File 'lib/knitpickr/scraper.rb', line 5

def yarn
  @yarn
end

Class Method Details

.all_fibersObject



43
44
45
# File 'lib/knitpickr/scraper.rb', line 43

def self.all_fibers
  @@all_fibers.uniq
end

.all_namesObject



39
40
41
# File 'lib/knitpickr/scraper.rb', line 39

def self.all_names
  @@all_names.uniq
end

.all_saleObject



55
56
57
# File 'lib/knitpickr/scraper.rb', line 55

def self.all_sale
  @@all_sale.uniq
end

.all_weightsObject



47
48
49
# File 'lib/knitpickr/scraper.rb', line 47

def self.all_weights
  @@all_weights.uniq
end

.all_yarnsObject



51
52
53
# File 'lib/knitpickr/scraper.rb', line 51

def self.all_yarns
  @@all_yarns
end

.make_yarnsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/knitpickr/scraper.rb', line 17

def self.make_yarns
  self.scrape_yarns
  all_yarns = @doc.css("div.listItem.book")

  all_yarns.each do |yarn|
    y = Knitpickr::Yarn.new(yarn.css(".titleSmall").first.attribute("title").value)
      @@all_yarns << y
    y.name = yarn.css(".titleSmall").first.attribute("title").value
      @@all_names << y.name
    y.weight = yarn.css(".yarnWeight")[1].text
      @@all_weights << y.weight
    y.fiber = yarn.css(".yarnWeight").first.text
      @@all_fibers << y.fiber
    y.price = yarn.css(".costSmall").first.text.strip
      if yarn.css(".listItemStatusTags").text == "Sale"
         y.sale = true
         @@all_sale << y
      end
    y
  end
end

.scrape_yarnsObject



13
14
15
# File 'lib/knitpickr/scraper.rb', line 13

def self.scrape_yarns
  @doc = Nokogiri::HTML(open("http://www.knitpicks.com/yarns/All_Knit_Picks_Yarn__L300198.html?showAll=yes"))
end