class Showfix::Episode
Constants
- VALID_EXTENSIONS
Video files, and some subtitles
Attributes
episode[RW]
extension[R]
file_no_ext[R]
filename[R]
options[R]
season[RW]
series[RW]
title[RW]
Public Class Methods
new(filename, options={})
click to toggle source
# File lib/showfix/episode.rb, line 12 def initialize(filename, options={}) raise ArgumentError, 'no filename' unless filename @filename = filename @options = { season: nil, series: nil }.merge(options) @cleaner = Cleaner.new(@options) @parser = Parser.new(@options) @season ||= options[:season] # if they passed in a default season @series ||= options[:series] @file_no_ext = @filename.chomp(File.extname(@filename)) @extension = File.extname(@filename).gsub(/\./, '').downcase self.update_episode_info end
Public Instance Methods
acceptable_file?()
click to toggle source
Determines if this is a file we should work with
# File lib/showfix/episode.rb, line 43 def acceptable_file? VALID_EXTENSIONS.include?(self.extension) end
has_episode_info?()
click to toggle source
# File lib/showfix/episode.rb, line 38 def has_episode_info? !@season.nil? && !@episode.nil? && @season.is_a?(Fixnum) && @episode.is_a?(Fixnum) end
skip?()
click to toggle source
# File lib/showfix/episode.rb, line 34 def skip? !acceptable_file? || !has_episode_info? end
to_formatted_s()
click to toggle source
# File lib/showfix/episode.rb, line 54 def to_formatted_s f_series = "" if @series && @series.strip.size > 0 f_series = "#{@series.strip}." end f_title = "" if @title && @title.strip.size > 0 f_title = ".#{@title.strip}" end "%sS%.2dE%.2d%s.%s" % [f_series, @season, @episode, f_title, @extension] end
update_episode_info()
click to toggle source
Extract info from the filename, and update fields as necessary
# File lib/showfix/episode.rb, line 70 def update_episode_info info = @parser.parse(@file_no_ext) if info keys = info.names @series ||= @cleaner.clean(info[:series]) if keys.include?('series') @season ||= info[:season].to_i if keys.include?('season') @episode ||= info[:episode].to_i if keys.include?('episode') @title ||= @cleaner.clean(info[:title]) if keys.include?('title') end end
update_season_episode(input)
click to toggle source
Parse season/episode info inputted by the user from the commandline
# File lib/showfix/episode.rb, line 48 def update_season_episode(input) # 1.1 => S1, E1 # 1.1-2 => S1, E1 & E2 # 1 => E1 (expect season to be from command line) end