class In_theater::Movie

Attributes

name[RW]
summary[RW]
url[RW]

Public Class Methods

all() click to toggle source
# File lib/In_theater/movie.rb, line 9
def self.all
  @@all ||= scrape_now_playing
end
find(id,array) click to toggle source
# File lib/In_theater/movie.rb, line 17
def self.find(id,array)
  array[id-1]
end
find_by_name(name, array) click to toggle source
# File lib/In_theater/movie.rb, line 21
def self.find_by_name(name, array)

  arr ||= array.collect.with_index(1) do |m, i|
    m, i = m, i if ( m.name.downcase.strip == name.downcase.strip ||
    m.name.split("(").first.strip.downcase == name.downcase.strip)
  end

  arr.detect {|n| n if n != nil}

end
movies() click to toggle source
# File lib/In_theater/movie.rb, line 13
def self.movies
  @@movies ||= self.all.collect { |d| custom_method(d.url)}
end
new(name = nil, url = nil) click to toggle source
# File lib/In_theater/movie.rb, line 4
def initialize(name = nil, url = nil)
  @name = name
  @url = url
end
summary(obj) click to toggle source
# File lib/In_theater/movie.rb, line 32
def self.summary(obj)

  doc ||= Nokogiri::HTML(open(obj.url.gsub("movieoverview", "plotsummary")))

  if doc.search("p[class='subpage-descriptive-content']").text == ""
    doc = Nokogiri::HTML(open(obj.url))
    puts "-------------- #{obj.name} summary --------------"
    puts doc.search("span[id='SynopsisTextLabel']").text

  else
    puts "-------------- #{obj.name} summary --------------"
    puts doc.search("p[class='subpage-descriptive-content']").text

  end

end

Private Class Methods

custom_method(arg) click to toggle source
# File lib/In_theater/movie.rb, line 65
def self.custom_method(arg)
  @doc = Nokogiri::HTML(open(arg))


  @movies = @doc.xpath("//a[@class='dark showtimes-movie-title']")
  #binding.pry

  #doc.search("a[class='dark showtimes-movie-title']").to_a.
  @movies.collect.with_index(1) { |name|
    new(name.children.text.strip, name.attributes.to_a[1][1].value )
  }
  #end

end
scrape_now_playing() click to toggle source
# File lib/In_theater/movie.rb, line 50
def self.scrape_now_playing
  puts "Enter zip code:"
  input = gets.strip

  @doc = Nokogiri::HTML(open("http://www.fandango.com/#{input.to_i}_movietimes/"))
  @theaters = @doc.xpath("//a[@class='light showtimes-theater-title']")
  #binding.pry

  @theaters.collect { |theater| new(theater.children.text.strip, theater.attributes.to_a[1][1].value) }

end

Private Instance Methods

doc() click to toggle source
# File lib/In_theater/movie.rb, line 80
def doc
  @doc ||= Nokogiri::HTML(open(self.url))
end