class TVShowRenamer::TVShowFile

Attributes

detected_episode[R]
detected_season[R]
episode[R]
filename[R]
season[R]

Public Class Methods

new(options = {}, filename = nil) click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 5
def initialize(options = {}, filename = nil)
  @options = options
  @filename = filename
end

Public Instance Methods

basename() click to toggle source

Lazy getters

# File lib/tvshow_renamer/tvshow_file.rb, line 24
def basename
  @basename ||= File.basename(@filename)
end
detect_season_and_episode() click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 57
def detect_season_and_episode
  regex = /(?<season>\d{1,2})(e|x|\.)?(?<episode>\d{2,})/i
  match = regex.match basename
  if match && match[:season] && match[:episode]
    @detected_season = match[:season].to_i
    send :season=, @detected_season
    @detected_episode = match[:episode].to_i
    send :episode=, @detected_episode
  end
end
dirname() click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 28
def dirname
  @dirname ||= File.dirname(@filename)
end
episode=(episode) click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 17
def episode=(episode)
  @episode = episode
  @new_basename = @new_filename = nil
end
extname() click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 32
def extname
  @extname ||= File.extname(@filename)
end
new_basename() click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 36
def new_basename
  unless @new_basename
    @new_basename = @options[:format].gsub('$n', @options[:tvshow_name])
                                     .gsub('$s', '%02i' % @season)
                                     .gsub('$e', '%02i' % @episode)
                                     .concat(extname)
    @new_filename = nil
  end
  @new_basename
end
new_filename() click to toggle source
# File lib/tvshow_renamer/tvshow_file.rb, line 47
def new_filename
  @new_filename ||= File.join dirname, new_basename
end
options_modified() click to toggle source

Active methods

# File lib/tvshow_renamer/tvshow_file.rb, line 53
def options_modified
  @new_basename = @new_filename = nil
end
season=(season) click to toggle source

Custom setters

# File lib/tvshow_renamer/tvshow_file.rb, line 12
def season=(season)
  @season = season
  @new_basename = @new_filename = nil
end