Class: MarvelMovies::Movie

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#release_dateObject

Returns the value of attribute release_date.



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

def release_date
  @release_date
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



32
33
34
# File 'lib/marvel_movies/movie.rb', line 32

def self.all
  self.scrape_movies
end

.dvdObject



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_allObject



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_dvdObject



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_upcomingObject



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_moviesObject



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

.upcomingObject



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_scrapeObject



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.rating = profile_data.css("span.block3").first.text.gsub(" Rating:  ", "").strip
    description = profile_data.css("div.featured-item-desc p").last
  else
    self.rating = 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