Class: In_theater::Movie
- Inherits:
-
Object
- Object
- In_theater::Movie
- Defined in:
- lib/In_theater/movie.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .find(id, array) ⇒ Object
- .find_by_name(name, array) ⇒ Object
- .movies ⇒ Object
- .summary(obj) ⇒ Object
Instance Method Summary collapse
-
#initialize(name = nil, url = nil) ⇒ Movie
constructor
A new instance of Movie.
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
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/In_theater/movie.rb', line 2 def name @name end |
#summary ⇒ Object
Returns the value of attribute summary.
2 3 4 |
# File 'lib/In_theater/movie.rb', line 2 def summary @summary end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/In_theater/movie.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
9 10 11 |
# File 'lib/In_theater/movie.rb', line 9 def self.all @@all ||= 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 |
.movies ⇒ Object
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 |