Class: RebelLegion::Scraper
- Inherits:
-
Object
- Object
- RebelLegion::Scraper
- Defined in:
- lib/rebel_legion/scraper.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
Instance Method Summary collapse
-
#get_and_make_costumes ⇒ Object
collects titles & urls of costume pages, sends to Costume class.
-
#get_categories(url) ⇒ Object
gets the main costume category list.
-
#get_costume_details ⇒ Object
scrapes each costume’s details and sends to that costume.
-
#initialize ⇒ Scraper
constructor
A new instance of Scraper.
-
#make_costume_categories ⇒ Object
sends data to CostumeCategory class.
Constructor Details
#initialize ⇒ Scraper
Returns a new instance of Scraper.
4 5 6 7 8 9 10 11 12 |
# File 'lib/rebel_legion/scraper.rb', line 4 def initialize puts "Loading....." @categories = {} @costume_pages = {} get_categories("http://www.rebellegion.com/costume-standards/by-category/") make_costume_categories get_and_make_costumes get_costume_details end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
2 3 4 |
# File 'lib/rebel_legion/scraper.rb', line 2 def categories @categories end |
Instance Method Details
#get_and_make_costumes ⇒ Object
collects titles & urls of costume pages, sends to Costume class
27 28 29 30 31 32 33 34 |
# File 'lib/rebel_legion/scraper.rb', line 27 def get_and_make_costumes # collects titles & urls of costume pages, sends to Costume class RebelLegion::CostumeCategory.all.each do |costume_category| doc = Nokogiri::HTML(open(costume_category.url)) doc.css("div#left-area article.entry-content.clearfix div.et_pt_blogentry.clearfix").each do |costume| RebelLegion::Costume.new(costume.css("h2.et_pt_title a").text, costume_category, costume.css("h2.et_pt_title a").attribute("href").value) end end end |
#get_categories(url) ⇒ Object
gets the main costume category list
14 15 16 17 18 19 |
# File 'lib/rebel_legion/scraper.rb', line 14 def get_categories(url) # gets the main costume category list doc = Nokogiri::HTML(open(url)) doc.css("div#left-area article.entry-content.clearfix p").each do |category| categories[category.css("a").text] = category.css("a").attribute("href").value end end |
#get_costume_details ⇒ Object
scrapes each costume’s details and sends to that costume
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rebel_legion/scraper.rb', line 36 def get_costume_details # scrapes each costume's details and sends to that costume RebelLegion::Costume.all.each do |costume| doc = Nokogiri::HTML(open(costume.url)) doc.css("div#left-area article.entry-content.clearfix div.et-box.et-shadow div.et-box-content").each do |item| if !item.css("ol li").empty? item.css("ol li").each { |subitem| costume.details << subitem.text } else costume.details << item.text end end end end |
#make_costume_categories ⇒ Object
sends data to CostumeCategory class
21 22 23 24 25 |
# File 'lib/rebel_legion/scraper.rb', line 21 def make_costume_categories # sends data to CostumeCategory class categories.each do |name, url| RebelLegion::CostumeCategory.new(name, url) end end |