Class: Movie
- Inherits:
-
Object
- Object
- Movie
- Defined in:
- lib/imdb_term/movie.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#content_rating ⇒ Object
Returns the value of attribute content_rating.
-
#director ⇒ Object
Returns the value of attribute director.
-
#genres ⇒ Object
Returns the value of attribute genres.
-
#id ⇒ Object
Returns the value of attribute id.
-
#release_year ⇒ Object
Returns the value of attribute release_year.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
-
#stars ⇒ Object
Returns the value of attribute stars.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .all ⇒ Object
- .create(movie_data) ⇒ Object
- .create_from_array(array) ⇒ Object
- .create_or_update(movie_data) ⇒ Object
- .find_by_id(id) ⇒ Object
- .find_by_title(title) ⇒ Object
- .find_or_create_by_id(id) ⇒ Object
- .new_from_array(array) ⇒ Object
Instance Method Summary collapse
-
#initialize(movie_data) ⇒ Movie
constructor
A new instance of Movie.
- #save ⇒ Object
- #update(movie_data) ⇒ Object
Constructor Details
#initialize(movie_data) ⇒ Movie
Returns a new instance of Movie.
7 8 9 10 11 |
# File 'lib/imdb_term/movie.rb', line 7 def initialize(movie_data) movie_data.each do |key, value| self.send("#{key}=", value) end end |
Instance Attribute Details
#content_rating ⇒ Object
Returns the value of attribute content_rating.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def @content_rating end |
#director ⇒ Object
Returns the value of attribute director.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def director @director end |
#genres ⇒ Object
Returns the value of attribute genres.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def genres @genres end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def id @id end |
#release_year ⇒ Object
Returns the value of attribute release_year.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def release_year @release_year end |
#runtime ⇒ Object
Returns the value of attribute runtime.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def runtime @runtime end |
#stars ⇒ Object
Returns the value of attribute stars.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def stars @stars end |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def summary @summary end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/imdb_term/movie.rb', line 3 def type @type end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/imdb_term/movie.rb', line 24 def self.all @@all end |
.create(movie_data) ⇒ Object
28 29 30 31 32 |
# File 'lib/imdb_term/movie.rb', line 28 def self.create(movie_data) movie = self.new(movie_data) movie.save movie end |
.create_from_array(array) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/imdb_term/movie.rb', line 52 def self.create_from_array(array) movies = Array.new array.each do |movie_data| movies << self.create_or_update(movie_data) end movies end |
.create_or_update(movie_data) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/imdb_term/movie.rb', line 34 def self.create_or_update(movie_data) movie = self.find_by_id(movie_data[:id]) if movie.nil? movie = self.create(movie_data) else movie.update(movie_data) end movie end |
.find_by_id(id) ⇒ Object
60 61 62 |
# File 'lib/imdb_term/movie.rb', line 60 def self.find_by_id(id) self.all.detect { |movie| movie.id.eql?(id) } end |
.find_by_title(title) ⇒ Object
69 70 71 |
# File 'lib/imdb_term/movie.rb', line 69 def self.find_by_title(title) self.all.detect { |movie| movie.title.casecmp(title) == 0 } end |
.find_or_create_by_id(id) ⇒ Object
64 65 66 67 |
# File 'lib/imdb_term/movie.rb', line 64 def self.find_or_create_by_id(id) movie = self.find_by_id(id) movie.nil? ? self.create({:id => id}) : movie end |
.new_from_array(array) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/imdb_term/movie.rb', line 44 def self.new_from_array(array) movies = Array.new array.each do |movie_data| movies << self.new(movie_data) end movies end |
Instance Method Details
#save ⇒ Object
19 20 21 22 |
# File 'lib/imdb_term/movie.rb', line 19 def save @@all << self self end |
#update(movie_data) ⇒ Object
13 14 15 16 17 |
# File 'lib/imdb_term/movie.rb', line 13 def update(movie_data) movie_data.each do |key, value| self.send("#{key}=", value) end end |