class MovieOrganizer::Movie
Attributes
tmdb_instance[R]
Public Class Methods
match?(filepath)
click to toggle source
Determine if the passed file is most likely a Movie
. If it is, that usually means the file was named with movie title and year somwehere in the filename
@return [Boolean] TmdbInstance
if likely a Movie
, false if not
# File lib/movie_organizer/movie.rb, line 13 def match?(filepath) base = basename(filepath) possible_year = possible_year_in_title(base) clean_title = sanitize(base).gsub(/[\s\.\-\_]\(?\s*\d+\s*\)?/, '') tmdb_instance = TmdbInstance.new(clean_title, possible_year) return tmdb_instance if tmdb_instance.movie? false end
new(filename, tmdb_instance)
click to toggle source
Calls superclass method
MovieOrganizer::Medium::new
# File lib/movie_organizer/movie.rb, line 31 def initialize(filename, tmdb_instance) super(filename) @tmdb_instance = tmdb_instance end
Private Class Methods
possible_year_in_title(title)
click to toggle source
# File lib/movie_organizer/movie.rb, line 24 def possible_year_in_title(title) title_with_year = sanitize(title) md = title_with_year.match(/(\d+)/) md ? md[1] : nil end
Public Instance Methods
process!()
click to toggle source
Set the target filename
# File lib/movie_organizer/movie.rb, line 38 def process! return nil unless tmdb_instance tmdb_instance.likely_match @target = File.join(target_dir, processed_filename) Logger.instance.info(" target file: [#{@target.green.bold}]") end
processed_filename()
click to toggle source
# File lib/movie_organizer/movie.rb, line 45 def processed_filename "#{title} (#{year})#{extname}" end
title()
click to toggle source
# File lib/movie_organizer/movie.rb, line 49 def title return sanitize(basename).gsub(/[\s\.\-\_]\(?\s*\d+\s*\)?/, '') unless tmdb_instance tmdb_instance.title end
year()
click to toggle source
# File lib/movie_organizer/movie.rb, line 54 def year return nil unless tmdb_instance tmdb_instance.year end
Private Instance Methods
target_dir()
click to toggle source
# File lib/movie_organizer/movie.rb, line 61 def target_dir @target_dir ||= File.join(MovieOrganizer.movie_directory, "#{title} (#{year})") end