Class: UpcomingMoviesInThePark::Scraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScraper

Returns a new instance of Scraper.



4
5
6
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 4

def initialize
  @showings =[]
end

Instance Attribute Details

#showingsObject

Returns the value of attribute showings.



2
3
4
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 2

def showings
  @showings
end

#urlsObject

Returns the value of attribute urls.



2
3
4
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 2

def urls
  @urls
end

Instance Method Details

#get_page(url) ⇒ Object



8
9
10
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 8

def get_page(url)
  Nokogiri::HTML(open(url))
end

#get_showing_detailsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 21

def get_showing_details
  self.urls.each do |url|
    doc = get_page("https://www.chicagoparkdistrict.com/#{url}")
    showing_hash ={}

    showing_hash[:date] = doc.css("p").first.text
    showing_hash[:park] = doc.css("div.field--name-node-title a").text

    if doc.css("b").text == ""
      showing_hash[:name] = doc.css("section#description strong").text
    else
      showing_hash[:name] = doc.css("b").text
    end

    @showings << showing_hash
  end
end

#get_showing_urlsObject



12
13
14
15
16
17
18
19
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 12

def get_showing_urls
  day = Date.today
  doc = get_page("https://www.chicagoparkdistrict.com/events/night-out-in-the-parks?field_event_category=404&field_event_start_date=#{day.year}-#{day.month}-#{day.day}&field_event_end_date=&field_event_movie_title=&field_event_movie_rating=All")

  doc2 = doc.css("div.view-content")

  @urls = doc2.children.css("div.views-field h2 a").map{ |x| x.attribute('href').value}
end

#make_showingsObject



39
40
41
42
43
44
45
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 39

def make_showings
  get_showing_urls
  get_showing_details
  @showings.each do |hash|
    UpcomingMoviesInThePark::Showing.create_from_hash(hash)
  end
end