Class MovieSeries
In: models/movie/movie_series.rb
Parent: Movie
MovieSeries TreeStructure Statistics Movie dot/f_32.png

Methods

Included Modules

TreeStructure Statistics

Constants

MOVIE_CONFIGURATION = self.superclass::MOVIE_CONFIGURATION.merge( { :languages => false, :countries => false, :production_companies => false, :budget => false, :runtime => false, :date => false, :status => false, :statistics => true, :reviews => false, :references => false, :cast => false, :votes => false, :trailers => false, :inheritable_cast => false }   Set configuration options for this class.

Public Class methods

[Source]

# File models/movie/movie_series.rb, line 131
  def self.best_sequel_gain
    sequels = []
    sequel_hash.keys.sort.each do |key|
      sequel_hash[key].each do |movies|
        return sequels if sequels.size == 10 or key > 0
        sequels << [ Movie.find(movies[0]), Movie.find(movies[1]) ]
      end
    end
    sequels
  end

[Source]

# File models/movie/movie_series.rb, line 175
  def self.best_sequel_hash
    data = sequel_data
    sequel_hash = {}
    while row = data.fetch_hash do
      series_id = 0 and next if row['vote_count'].to_i < MOVIE_VOTE_COUNT_THRESHOLD
      if series_id != row['parent']
        series_id = row['parent']
        last_vote = row['vote'].to_i
        last_id   = row['child'].to_i
        next
      end
      vote_sum = row['vote'].to_f
      sequel_hash[ vote_sum ] ||= []
      sequel_hash[ vote_sum ] << [ last_id, row['child'].to_i ]
      last_id   = row['child'].to_i
      last_vote = row['vote'].to_i 
    end
    sequel_hash      
  end

[Source]

# File models/movie/movie_series.rb, line 120
  def self.best_sequels
    sequels = []
    best_sequel_hash.keys.sort.reverse.each do |key|
      best_sequel_hash[key].each do |movies|
        sequels << [ Movie.find(movies[0]), Movie.find(movies[1]) ]
        return sequels if sequels.size == 10
      end
    end
    sequels
  end

[Source]

# File models/movie/movie_series.rb, line 39
  def self.popular
    MovieSeries.find(:all, 
                     :limit => 10,
                     :order => "popularity DESC")
  end

[Source]

# File models/movie/movie_series.rb, line 195
  def self.sequel_data
    connection.execute("SELECT parent.id as parent, child.id as child, child.vote as vote, child.votes_count as vote_count
                        FROM   movies as parent, movies as child
                        WHERE  child.parent_id = parent.id and parent.type = 'MovieSeries' and 
                               child.type = 'Movie' and child.end is not NULL
                        ORDER  by parent.id, child.end")
  end

[Source]

# File models/movie/movie_series.rb, line 154
  def self.sequel_hash
    series_id = 0
    data = sequel_data
    sequel_hash = {}
    while row = data.fetch_hash do
      series_id = 0 and next if row['vote_count'].to_i < MOVIE_VOTE_COUNT_THRESHOLD
      if series_id != row['parent']
        series_id = row['parent']
        last_vote = row['vote'].to_i
        last_id   = row['child'].to_i
        next
      end
      vote_diff = last_vote - row['vote'].to_f
      sequel_hash[ vote_diff ] ||= []
      sequel_hash[ vote_diff ] << [ last_id, row['child'].to_i ]
      last_id   = row['child'].to_i
      last_vote = row['vote'].to_i 
    end
    sequel_hash
  end

[Source]

# File models/movie/movie_series.rb, line 31
  def self.valid_children
    [ Movie, Series ]
  end

[Source]

# File models/movie/movie_series.rb, line 35
  def self.valid_parents
    []
  end

[Source]

# File models/movie/movie_series.rb, line 142
  def self.worst_sequel_drop
    sequels = []
    sequel_hash.keys.sort.reverse.each do |key|
      sequel_hash[key].each do |movies|
        return sequels if sequels.size == 10 or key < 0
        sequels << [ Movie.find(movies[0]), Movie.find(movies[1]), key ]
      end
    end
    sequels
  end

Public Instance methods

[Source]

# File models/movie/movie_series.rb, line 45
  def all_movies( limit, offset )
    all_children.delete_if { |child| ![ Movie, Episode ].include?(child.class) }
  end

Overwrite default Movie#directors method

[Source]

# File models/movie/movie_series.rb, line 50
  def directors
    directors = []
    self.children.each { |m|
      m.directors.slice(0,1).each { |d| directors.push(d) }
    }
    directors.uniq
  end

Fetch the last production date of all children

[Source]

# File models/movie/movie_series.rb, line 69
  def end
    dates = self.children.map(&:end).compact
    #self.children.each { |c| 
    #  dates.push(c.end) unless c.end.nil?
    #}
    # set the end-date for this movie series if it has been changed
    # (like a child has been added or an existing has been removed)
    # Changing the :end attribute does not fire a logging, as :end
    # is set to be unloggable for series.
    last = dates.sort.last
    update_attribute_with_validation_skipping( :end, last ) unless self.attributes["end"] == last
    last
  end

[Source]

# File models/movie/movie_series.rb, line 103
  def end_year
    return self.end.year unless self.end.nil?
  end

[Source]

# File models/movie/movie_series.rb, line 83
  def production_year
    if self.children.empty?
      nil
    else
      if not self.end.nil? and not self.start.nil?
        if self.start.year == self.end.year
          self.start.year
        else
          Range.new( self.start.year, self.end.year )
        end
      else
        self.start.nil? ? ( self.end.nil? ? nil : self.end.year ) : self.start.year
      end
    end
  end

Fetch the first production date of all children

[Source]

# File models/movie/movie_series.rb, line 59
  def start
    start = []
    self.children.each { |c| 
      start.push(c.start) unless c.start.nil?
      start.push(c.end) unless c.end.nil?
    }
    start.sort.first
  end

[Source]

# File models/movie/movie_series.rb, line 99
  def start_year
    return self.start.year unless self.start.nil?
  end

Calculate the avarage vote of all children

[Source]

# File models/movie/movie_series.rb, line 108
  def vote
    vote = 0
    size = 0
    self.children.each do |c|
      if c.vote > 0
        vote = vote + c.vote
        size = size + 1
      end
    end
    (size > 0) ? (vote / size) : 0
  end

[Validate]