Class: TomatoPower::Movie

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

Overview

A Movie

Constant Summary collapse

MOVIE_METHOD_ALIAS =

Aliased API methods for a better interface.

{
  :info => :movie_info,
  :full_cast => :movie_cast,
  :clips => :movie_clips,
  :reviews => :movie_reviews,
  :similar => :movie_similar,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(movie = {}) ⇒ Movie

Returns a new instance of Movie.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tomato_power/movie/movie.rb', line 9

def initialize movie={}
  @id = movie["id"] 
  @title = movie["title"]
  @year = movie["year"]
  @genres = movie["genres"]
  @critics_consensus = movie["critics_consensus"]
  @mpaa_rating = movie["mpaa_rating"]
  @runtime = movie["runtime"]
  @release_dates = movie["release_dates"]
  @ratings = movie["ratings"]
  @synopsis = movie["synopsis"]
  @posters = movie["posters"]
  @abridged_cast = movie["abridged_cast"]
  @alternate_ids = movie["alternate_ids"]
  @links = movie["links"]
  @directors = movie["abridged_directors"]
  @studio = movie["studio"]

  @api = TomatoPower::api
  Movie.define_movie_methods(*MOVIE_METHOD_ALIAS.keys)
end

Instance Attribute Details

#alternate_idsObject (readonly)

Returns the value of attribute alternate_ids.



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

def alternate_ids
  @alternate_ids
end

#critics_consensusObject (readonly)

Returns the value of attribute critics_consensus.



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

def critics_consensus
  @critics_consensus
end

#directorsObject (readonly)

Returns the value of attribute directors.



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

def directors
  @directors
end

#genresObject (readonly)

Returns the value of attribute genres.



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

def genres
  @genres
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#infoObject (readonly)

Returns the value of attribute info.



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

def info
  @info
end

Returns the value of attribute links.



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

def links
  @links
end

#mpaa_ratingObject (readonly)

Returns the value of attribute mpaa_rating.



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

def mpaa_rating
  @mpaa_rating
end

#ratingsObject (readonly)

Returns the value of attribute ratings.



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

def ratings
  @ratings
end

#release_datesObject (readonly)

Returns the value of attribute release_dates.



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

def release_dates
  @release_dates
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



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

def runtime
  @runtime
end

#studioObject (readonly)

Returns the value of attribute studio.



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

def studio
  @studio
end

#synopsisObject (readonly)

Returns the value of attribute synopsis.



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

def synopsis
  @synopsis
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Class Method Details

.define_movie_methods(*methods) ⇒ Object

Note:

TOMATO_METHODS is a hash containing all of the Rotten Tomatoes API calls.

Defines methods that are in MOVIE_METHOD_ALIAS. Straight up delegation is not used because @id needs to be inserted into options before calling the method.

Parameters:

  • methods (Array)

    methods to be created.

  • options (Hash)

    options for function call.



59
60
61
62
63
64
65
66
# File 'lib/tomato_power/movie/movie.rb', line 59

def self.define_movie_methods(*methods)
  methods.each do |method|
    define_method(method) do |options={}|
      options[:movie_id] = @id
      @api.send(MOVIE_METHOD_ALIAS[method], options)
    end
  end
end

Instance Method Details

#castObject

Note:

this returns the abridged cast.

cast from a movie



49
50
51
# File 'lib/tomato_power/movie/movie.rb', line 49

def cast 
  @actors ||= TomatoPower::Parser::parse_cast @abridged_cast
end

#postersObject

Poster for a movie

Returns:

  • poster links



42
43
44
# File 'lib/tomato_power/movie/movie.rb', line 42

def posters
  @poster_links ||= TomatoPower::Parser::parse_posters @posters
end