Class: MostHauntedCli::Scraper
- Inherits:
-
Object
- Object
- MostHauntedCli::Scraper
- Defined in:
- lib/most_haunted/scraper.rb
Constant Summary collapse
- URL =
"https://hauntedrooms.com/haunted-places"- @@america =
[]
- @@states =
[]
- @@urls =
[]
Class Method Summary collapse
-
.all_states ⇒ Object
Individual State Information.
- .america ⇒ Object
- .scrape_america ⇒ Object
- .scrape_america_descriptions ⇒ Object
- .scrape_state_locations(input) ⇒ Object
- .states ⇒ Object
- .urls ⇒ Object
Class Method Details
.all_states ⇒ Object
Individual State Information
30 31 32 |
# File 'lib/most_haunted/scraper.rb', line 30 def self.all_states @@states end |
.america ⇒ Object
9 10 11 |
# File 'lib/most_haunted/scraper.rb', line 9 def self.america @@america end |
.scrape_america ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/most_haunted/scraper.rb', line 13 def self.scrape_america doc = Nokogiri::HTML(open(URL)) list = doc.search("h3.section-title span").children list.each do |l| self.america << l.text.strip end MostHauntedCli::America.create(self.america) end |
.scrape_america_descriptions ⇒ Object
22 23 24 25 26 |
# File 'lib/most_haunted/scraper.rb', line 22 def self.scrape_america_descriptions doc = Nokogiri::HTML(open(URL)) paragraphs = doc.search("div.entry-content p") paragraphs end |
.scrape_state_locations(input) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/most_haunted/scraper.rb', line 48 def self.scrape_state_locations(input) list = [] title = [] u = MostHauntedCli::States.all url = u[input.to_i - 1].url doc = Nokogiri::HTML(open("https://hauntedrooms.com"+"#{url}")) t = doc.search("h1.entry-title").text.strip title << t locations = doc.search("div.entry-content h2").children if locations.empty? == true locations = doc.search("div.entry-content i").children if locations.empty? == true locations = doc.search("h3.section-title.clearfix.title_center").children end end locations.each do |l| list << l.text.gsub("end section_title", " ") unless l.text == "(Stay Here)" || l.text == "(Book Now)" || l.text == "(Book a Room)" end puts "--" * 20 puts title puts "--" * 20 puts '' list end |
.states ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/most_haunted/scraper.rb', line 38 def self.states doc = Nokogiri::HTML(open(URL)) states = doc.search("tbody li").children states.each do |t| self.all_states << t.text self.urls << t.attribute("href").value end MostHauntedCli::States.create_state(self.all_states) end |
.urls ⇒ Object
34 35 36 |
# File 'lib/most_haunted/scraper.rb', line 34 def self.urls @@urls end |