Class: Scraper

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

Class Method Summary collapse

Class Method Details

.attraction_details(attraction, city) ⇒ Object



44
45
46
47
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/undercover_tourist_cli/scraper.rb', line 44

def self.attraction_details(attraction, city)
        city.attractions.select.with_index do |val, index|
if val == attraction.name
  @selected_attraction_url = city.urls[index]
  attraction.url=(@selected_attraction_url)
end
        end
        attraction_info = Nokogiri::HTML(open(@selected_attraction_url))
        node = attraction_info.css('.reviewpads')
if node.empty?
  attraction.rating=("N/A")
else
  node1 = attraction_info.css('.reviewpads').attribute('class').value.split[1].split('star')
  attraction.rating=(node1[0].capitalize + " Stars")
end
        node2 = attraction_info.css('.about-attraction').children.css('p').text
  if node2.empty?
    attraction.description=("N/A")
  else
   attraction.description=(node2)
  end
        node3 = attraction_info.css('.daydetail')
   if node3.nil?
     attraction.current_crowd_rating=("N/A")
   else
     attraction.current_crowd_rating=(node3.first.text)
   end
        node4 = attraction_info.css('.fff-attractions').children.css('li').children.css('a')
     node4.each do |node|
       attraction.priority_attractions << node.text
     end
   if attraction.priority_attractions.empty?
     attraction.priority_attractions=("N/A")
   end
        node5 = attraction_info.css('.calattraction').attribute('data-filter-ids').value
    if node5.include?('None')
      attraction.hours=("N/A")
    elsif 
      node6 = attraction_info.css('calattraction .filterableitem').nil?
        attraction.hours=("N/A")
    elsif 
      node6 = attraction_info.css('.calattraction .filterableitem .caltime')[0].nil?
       attraction.hours=("N/A")
    else 
      node6 = attraction_info.css('.calattraction .filterableitem .caltime')[0].text.strip
        if node6 == nil
          attraction.hours=("N/A")
        elsif node6.include?('EMH')
          node7 = attraction_info.css('.calattraction .filterableitem .caltime')[1].text.strip
             hours = "#{node6} " + "/ #{node7}"
             attraction.hours=(hours)
        else 
             hours = "#{node6}" 
             attraction.hours=(hours)
        end 
    end  
end

.parse_page(city) ⇒ Object



6
7
8
9
# File 'lib/undercover_tourist_cli/scraper.rb', line 6

def self.parse_page(city)
  @page = Nokogiri::HTML(open(@base_path + "/#{city.name.downcase}"))
  @page
end

.scrape_city_attractions(city) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/undercover_tourist_cli/scraper.rb', line 16

def self.scrape_city_attractions(city)
@city_page = Nokogiri::HTML(open(@base_path + "/#{city.name.downcase}" +"/attractions"))
node = @city_page.css('.tiletitle')
  node.each do |node|
    if node.text != "Attraction" 
      city.attractions << node.text unless city.attractions.include?(node.text) 
    end 
  end 
  city.attractions.each do |object|
    new = Attractions.new(object) 
    new.city=(city) 
  end 
  scrape_urls(city)
end

.scrape_city_summary(city) ⇒ Object



11
12
13
14
# File 'lib/undercover_tourist_cli/scraper.rb', line 11

def self.scrape_city_summary(city)
  Scraper.parse_page(city)
  city.city_summary = @page.css(".cityblurb").children.css("p").text
end

.scrape_urls(city) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/undercover_tourist_cli/scraper.rb', line 31

def self.scrape_urls(city)
  @attraction_page = Nokogiri::HTML(open(@base_path + "/#{city.name.downcase}" +"/attractions"))
  node = @attraction_page.css('.tile')
  @url_list = []
    node.each do |node|
       url = node.children.css('a').attribute('href')
          if url != nil 
           @url_list << @base_path + url.value unless @url_list.include?(@base_path + url.value)
           city.urls=(@url_list)
        end
    end 
end