Class: NewYorkFilms::FilmFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/new_york_films/film_finder.rb

Constant Summary collapse

@@all_films =
[]
@@theaters =
[]

Class Method Summary collapse

Class Method Details

.allObject



29
30
31
# File 'lib/new_york_films/film_finder.rb', line 29

def self.all
  @@all_films
end

.scraperObject



33
34
35
36
37
38
39
40
41
42
43
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
# File 'lib/new_york_films/film_finder.rb', line 33

def self.scraper
doc = Nokogiri::HTML(open("http://www.screenslate.com/"))

doc.search("ul li.screenings__venue___2EEUR li.screenings__screening___2wxaa").map do |film|
  @@all_films << screening = NewYorkFilms::Screening.new

    if film.parent.parent.css("h3") != nil
      screening.theater = film.parent.parent.css("h3").text
    else
      screening.theater = "not provided"
    end

    if film.css("a.screening__link___1rTIP") != nil
      screening.title = film.css("a.screening__link___1rTIP").text
    else
      screening.title = "not provided"
    end


    if film.search("div.screening__details___2yckE span")[0] != nil
      screening.director = film.search("div.screening__details___2yckE span")[0].text
    else
      screening.director = "Not listed."
    end

    if film.search("div.screening__details___2yckE span")[1] != nil
      screening.year = film.search("div.screening__details___2yckE span")[1].text
    else
      screening.year = "not provided"
    end

    if film.search("div.screening__details___2yckE span")[2] != nil
      screening.length = film.search("div.screening__details___2yckE span")[2].text
    else
      screening.length = "not provided"
    end

    if film.search("div.screening__showtimespacing___17fBg span.screening__showtime___3oJD6") != nil
      screening.times = film.search("div.screening__showtimespacing___17fBg span.screening__showtime___3oJD6").text.gsub("pm","pm  ").gsub("am", "am  ")
    else
      screening.times = "not provided"
    end

    if film.search("a.screening__link___1rTIP").attribute('href') == nil
          film.attribute('href').value = "http://www.screenslate.com/"
    end

    screening.website = film.search("a.screening__link___1rTIP").attribute("href").value

    contact = film.parent.parent.css("a").attribute("href").value
    venue = Nokogiri::HTML(open("http://www.screenslate.com#{contact}"))

    if venue.css("div.venue__info___2bLnH p") != nil
      screening.location = venue.css("div.venue__info___2bLnH p").first.text.gsub("Location ", "") if venue.css("div.venue__info___2bLnH p").first.text.include?(", NY")
      screening.location = venue.css("div.venue__info___2bLnH p")[1].text.gsub("Location ", "") if venue.css("div.venue__info___2bLnH p")[1].text.include?(", NY")
    else
      screening.location = "please see theater's website."
    end
  end
end

.theater_scraperObject



94
95
96
97
98
99
100
# File 'lib/new_york_films/film_finder.rb', line 94

def self.theater_scraper
  doc = Nokogiri::HTML(open("http://www.screenslate.com/"))
  doc.search("ul li.screenings__venue___2EEUR li.screenings__screening___2wxaa").each do |film|
    @@theaters << film.parent.parent.css("h3").text
  end
  @@theaters
end

.theatersObject



25
26
27
# File 'lib/new_york_films/film_finder.rb', line 25

def self.theaters
  @@theaters
end