Class: In_theater::Movie

Inherits:
Object
  • Object
show all
Defined in:
lib/In_theater/movie.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil) ⇒ Movie

Returns a new instance of Movie.



4
5
6
7
# File 'lib/In_theater/movie.rb', line 4

def initialize(name = nil, url = nil)
  @name = name
  @url = url
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/In_theater/movie.rb', line 2

def name
  @name
end

#summaryObject

Returns the value of attribute summary.



2
3
4
# File 'lib/In_theater/movie.rb', line 2

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/In_theater/movie.rb', line 2

def url
  @url
end

Class Method Details

.allObject



9
10
11
# File 'lib/In_theater/movie.rb', line 9

def self.all
  @@all ||= scrape_now_playing
end

.find(id, array) ⇒ Object



17
18
19
# File 'lib/In_theater/movie.rb', line 17

def self.find(id,array)
  array[id-1]
end

.find_by_name(name, array) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# 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

.moviesObject



13
14
15
# File 'lib/In_theater/movie.rb', line 13

def self.movies
  @@movies ||= self.all.collect { |d| custom_method(d.url)}
end

.summary(obj) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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