class MostHauntedCli::Scraper

Constants

URL

Public Class Methods

all_states() click to toggle source

Individual State Information

# File lib/most_haunted/scraper.rb, line 30
def self.all_states
    @@states
end
america() click to toggle source
# File lib/most_haunted/scraper.rb, line 9
def self.america
    @@america
end
scrape_america() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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
                if locations.empty? == true
                  locations = doc.search("div.container.section-title-container").children
                end
            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() click to toggle source
# 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() click to toggle source
# File lib/most_haunted/scraper.rb, line 34
def self.urls
   @@urls
end