Sha256: fc3b51d07641cc9c453fd7ad5378b1b924bd8ced4ee20d737ae11c1b52040926
Contents?: true
Size: 1.76 KB
Versions: 2
Compression:
Stored size: 1.76 KB
Contents
module TMDBParty class Movie include Attributes attr_reader :tmdb attributes :name, :overview, :id, :score, :imdb_id, :movie_type, :url, :popularity, :alternative_title attributes :released attributes :id, :type => Integer attributes :popularity, :score, :type => Float attributes :posters, :backdrops, :lazy => :get_info! attributes :homepage, :lazy => :get_info! attributes :trailer, :lazy => :get_info! attributes :runtime, :lazy => :get_info!, :type => Integer attributes :genres, :lazy => :get_info!, :type => Genre attributes :cast, :lazy => :get_info!, :type => Person alias_method :flattened_posters, :posters alias_method :flattened_backdrops, :backdrops def initialize(values, tmdb) @tmdb = tmdb self.attributes = values end def get_info! movie = tmdb.get_info(self.id) @attributes.merge!(movie.attributes) if movie @loaded = true end def directors find_cast('Director') end def actors find_cast('Actor') end def writers find_cast('Writer') end def posters process_art(flattened_posters) end def backdrops process_art(flattened_backdrops) end private def process_art(art) image_groups = {} art.each do |image_hash| the_image = image_hash["image"] if image_groups[the_image["id"]] image_groups[the_image["id"]][the_image["size"]] = the_image["url"] else image_groups[the_image["id"]] = {the_image["size"] => the_image["url"]} end end image_groups.values end def find_cast(type) return [] unless cast guys = cast.select{|c| c.job == type} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tmdb_party-0.4.1 | lib/tmdb_party/movie.rb |
tmdb_party-0.4.0 | lib/tmdb_party/movie.rb |