Class: UpcomingMoviesInThePark::Scraper
- Inherits:
-
Object
- Object
- UpcomingMoviesInThePark::Scraper
- Defined in:
- lib/upcoming_movies_in_the_park/scraper.rb
Instance Attribute Summary collapse
-
#showings ⇒ Object
Returns the value of attribute showings.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
- #get_page(url) ⇒ Object
- #get_showing_details ⇒ Object
- #get_showing_urls ⇒ Object
-
#initialize ⇒ Scraper
constructor
A new instance of Scraper.
- #make_showings ⇒ Object
Constructor Details
#initialize ⇒ Scraper
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
#showings ⇒ Object
Returns the value of attribute showings.
2 3 4 |
# File 'lib/upcoming_movies_in_the_park/scraper.rb', line 2 def showings @showings end |
#urls ⇒ Object
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_details ⇒ Object
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_urls ⇒ Object
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_showings ⇒ Object
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 |