Class: Moviesort::Sorter::TV

Inherits:
Object
  • Object
show all
Defined in:
lib/moviesort/sorter.rb

Constant Summary collapse

VALID_FILE_TYPES =
%w{avi mkv mov mp4}

Instance Method Summary collapse

Constructor Details

#initialize(output_dir) ⇒ TV

Returns a new instance of TV.



8
9
10
11
# File 'lib/moviesort/sorter.rb', line 8

def initialize(output_dir)
  @output_dir = output_dir
  @notifiers = []
end

Instance Method Details

#add_notifier(notifier) ⇒ Object



13
14
15
16
# File 'lib/moviesort/sorter.rb', line 13

def add_notifier(notifier)
  raise "Notifier object must respond to notify" unless notifier.respond_to?(:notify)
  @notifiers << notifier
end

#sort_directory(path) ⇒ Object



18
19
20
21
22
# File 'lib/moviesort/sorter.rb', line 18

def sort_directory(path)
  movie_files_in_directory(path).each do |file|
    sort_file(file)
  end
end

#sort_file(path) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/moviesort/sorter.rb', line 24

def sort_file(path)
  tv_show = Moviesort::TVShow.parse(File.basename(path))
  target_path = File.join(@output_dir, tv_show.target_path)
  FileUtils.mkdir_p(target_path)
  FileUtils.mv(path, File.join(target_path, tv_show.target_filename))
  notify(tv_show)
end