Class: Knitpickr::Scraper
- Inherits:
-
Object
- Object
- Knitpickr::Scraper
- Defined in:
- lib/knitpickr/scraper.rb
Constant Summary collapse
- @@all_names =
[]
- @@all_fibers =
[]
- @@all_weights =
[]
- @@all_yarns =
[]
- @@all_sale =
[]
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#yarn ⇒ Object
Returns the value of attribute yarn.
Class Method Summary collapse
- .all_fibers ⇒ Object
- .all_names ⇒ Object
- .all_sale ⇒ Object
- .all_weights ⇒ Object
- .all_yarns ⇒ Object
- .make_yarns ⇒ Object
- .scrape_yarns ⇒ Object
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
5 6 7 |
# File 'lib/knitpickr/scraper.rb', line 5 def doc @doc end |
#yarn ⇒ Object
Returns the value of attribute yarn.
5 6 7 |
# File 'lib/knitpickr/scraper.rb', line 5 def yarn @yarn end |
Class Method Details
.all_fibers ⇒ Object
43 44 45 |
# File 'lib/knitpickr/scraper.rb', line 43 def self.all_fibers @@all_fibers.uniq end |
.all_names ⇒ Object
39 40 41 |
# File 'lib/knitpickr/scraper.rb', line 39 def self.all_names @@all_names.uniq end |
.all_sale ⇒ Object
55 56 57 |
# File 'lib/knitpickr/scraper.rb', line 55 def self.all_sale @@all_sale.uniq end |
.all_weights ⇒ Object
47 48 49 |
# File 'lib/knitpickr/scraper.rb', line 47 def self.all_weights @@all_weights.uniq end |
.all_yarns ⇒ Object
51 52 53 |
# File 'lib/knitpickr/scraper.rb', line 51 def self.all_yarns @@all_yarns end |
.make_yarns ⇒ Object
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_yarns ⇒ Object
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 |