Class: MostHauntedCli::Scraper

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

Constant Summary collapse

URL =
"https://hauntedrooms.com/haunted-places"
@@america =
[]
@@s =
[]
@@urls =
[]

Class Method Summary collapse

Class Method Details

.americaObject



9
10
11
# File 'lib/most_haunted/scraper.rb', line 9

def self.america
    @@america 
end

.sObject



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

def self.s
    @@s
end

.scrape_americaObject



21
22
23
24
25
26
27
28
# File 'lib/most_haunted/scraper.rb', line 21

def self.scrape_america
    doc = Nokogiri::HTML(open(URL))
    new = doc.search("h3.section-title.clearfix span").children
    new.each do |list|
        self.america << list.text
    end
    MostHauntedCli::America.create(self.america)
end

.scrape_america_descriptionsObject



30
31
32
33
34
# File 'lib/most_haunted/scraper.rb', line 30

def self.scrape_america_descriptions
    doc = Nokogiri::HTML(open(URL))
    paragraphs = doc.search("div.entry-content p")
    paragraphs
end

.scrape_state_locations(input) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/most_haunted/scraper.rb', line 66

def self.scrape_state_locations(input)
    list = []
    u = MostHauntedCli::States.haunted
    url = u[input.to_i - 1].url
        doc = Nokogiri::HTML(open(url)) 
        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
    list
end

.scrape_state_title(input) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/most_haunted/scraper.rb', line 56

def self.scrape_state_title(input)
    title = []
    u = MostHauntedCli::States.haunted
    url = u[input - 1].url
    doc = Nokogiri::HTML(open(url)) 
    t = doc.search("h1.entry-title").text
        title << t
        puts title
end

.scrape_state_urlObject



47
48
49
50
51
52
53
54
# File 'lib/most_haunted/scraper.rb', line 47

def self.scrape_state_url
    doc = Nokogiri::HTML(open(URL))
    states = doc.search("tbody li").children
    states.each do |t|
        self.urls << t.attribute("href").value
    end
    self.urls
end

.statesObject

Individual State Information



38
39
40
41
42
43
44
45
# 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.s << t.text
    end
    MostHauntedCli::States.create_state(self.s)
end

.urlsObject



17
18
19
# File 'lib/most_haunted/scraper.rb', line 17

def self.urls
   @@urls 
end