Class: MarvelMovies::Movie
- Inherits:
-
Object
- Object
- MarvelMovies::Movie
- Defined in:
- lib/marvel_movies/movie.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .dvd ⇒ Object
- .find_movie(array, index) ⇒ Object
- .list_all ⇒ Object
- .list_dvd ⇒ Object
- .list_upcoming ⇒ Object
- .scrape_movies ⇒ Object
- .upcoming ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/marvel_movies/movie.rb', line 2 def description @description end |
#rating ⇒ Object
Returns the value of attribute rating.
2 3 4 |
# File 'lib/marvel_movies/movie.rb', line 2 def @rating end |
#release_date ⇒ Object
Returns the value of attribute release_date.
2 3 4 |
# File 'lib/marvel_movies/movie.rb', line 2 def release_date @release_date end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/marvel_movies/movie.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/marvel_movies/movie.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/marvel_movies/movie.rb', line 32 def self.all self.scrape_movies end |
.dvd ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/marvel_movies/movie.rb', line 61 def self.dvd today = Date.today movie_list = [] self.scrape_movies.map do |movie| movie_date = Date.parse(movie.release_date) if today >= movie_date movie_list << movie end end movie_list end |
.find_movie(array, index) ⇒ Object
80 81 82 |
# File 'lib/marvel_movies/movie.rb', line 80 def self.find_movie(array, index) array[index-1] end |
.list_all ⇒ Object
36 37 38 39 40 |
# File 'lib/marvel_movies/movie.rb', line 36 def self.list_all self.all.map.with_index(1) do |movie, i| puts "#{i}. #{movie.title}" end end |
.list_dvd ⇒ Object
74 75 76 77 78 |
# File 'lib/marvel_movies/movie.rb', line 74 def self.list_dvd self.dvd.map.with_index(1) do |movie, i| puts "#{i}. #{movie.title}" end end |
.list_upcoming ⇒ Object
55 56 57 58 59 |
# File 'lib/marvel_movies/movie.rb', line 55 def self.list_upcoming self.upcoming.map.with_index(1) do |movie, i| puts "#{i}. #{movie.title}" end end |
.scrape_movies ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/marvel_movies/movie.rb', line 4 def self.scrape_movies data = Nokogiri::HTML(open("http://marvel.com/movies/all")) movie_array = [] data.css("div.JCMultiRow div.row-item").collect do |movies| movie = self.new movie.title = movies.css("div.row-item-text h5 a").text movie.release_date = movies.css("div.row-item-text p.media-item-meta").text movie.url = "http://marvel.com" + movies.css("div.row-item-text h5 a").attr("href").value movie_array << movie end movie_array.uniq end |
.upcoming ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/marvel_movies/movie.rb', line 42 def self.upcoming today = Date.today movie_list = [] self.scrape_movies.map do |movie| movie_date = Date.parse(movie.release_date) if today < movie_date movie_list << movie end end movie_list end |
Instance Method Details
#profile_scrape ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/marvel_movies/movie.rb', line 18 def profile_scrape profile_data = Nokogiri::HTML(open(self.url)) if profile_data.css("span.block3")[0] self. = profile_data.css("span.block3").first.text.gsub(" Rating: ", "").strip description = profile_data.css("div.featured-item-desc p").last else self. = profile_data.css("div.details p").last.text.strip.gsub("Rating: ", "") description = profile_data.css("div#pull-quote h1") end description.css("a").remove self.description = description.text.gsub( /\n|\t|\r|[ ]{2,}/, "" ).strip end |