class Showfix::CLI

Public Instance Methods

rename() click to toggle source
# File lib/showfix/cli.rb, line 27
def rename

  path = File.absolute_path(options['directory'])

  if options['directory'] != "."
    say "Scanning directory #{path}:"
    say ""
  end

  episode_opts = {
    series: options['series'],
    season: options['season'],
    year: options['strip-year'],
    flags: options['clean']
  }

  Dir["#{path}/*"].each do |file|
    basename = File.basename(file)
    episode = Showfix::Episode.new(basename, episode_opts)

    if episode.acceptable_file?
      say "#{basename} => "

      # unless episode.has_episode_info?
      #   input = ask "Enter the Season.Episode (1.1): "
      #   episode.update_season_episode(input)
      # end

      # If they fixed it
      if episode.has_episode_info?
        say "#{episode.to_formatted_s}"

        unless options['pretend']
          rename_file(file, episode.to_formatted_s)
        end

      else
        say "SKIPPED"
      end

    end
  end
end

Private Instance Methods

rename_file(source_path, dest_file) click to toggle source
# File lib/showfix/cli.rb, line 73
def rename_file(source_path, dest_file)
  raise IOError, 'source file not found' unless File.file?(source_path)

  dest_path = File.join(File.dirname(source_path), dest_file)

  raise IOError, 'destination already exists' if File.file?(dest_path)

  begin
    File.rename(source_path, dest_path)
  rescue SystemCallError
    puts "Unable to rename file #{File.basename(source_path)}"
  end
end