Class: Showfix::Episode
- Inherits:
-
Object
- Object
- Showfix::Episode
- Defined in:
- lib/showfix/episode.rb
Constant Summary collapse
- VALID_EXTENSIONS =
Video files, and some subtitles
%w(avi mkv mp4 mpg mpeg mov m4v srt)
Instance Attribute Summary collapse
-
#episode ⇒ Object
Returns the value of attribute episode.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#file_no_ext ⇒ Object
readonly
Returns the value of attribute file_no_ext.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#season ⇒ Object
Returns the value of attribute season.
-
#series ⇒ Object
Returns the value of attribute series.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#acceptable_file? ⇒ Boolean
Determines if this is a file we should work with.
- #has_episode_info? ⇒ Boolean
-
#initialize(filename, options = {}) ⇒ Episode
constructor
A new instance of Episode.
- #skip? ⇒ Boolean
- #to_formatted_s ⇒ Object
-
#update_episode_info ⇒ Object
Extract info from the filename, and update fields as necessary.
-
#update_season_episode(input) ⇒ Object
Parse season/episode info inputted by the user from the commandline.
Constructor Details
#initialize(filename, options = {}) ⇒ Episode
Returns a new instance of Episode.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/showfix/episode.rb', line 12 def initialize(filename, ={}) raise ArgumentError, 'no filename' unless filename @filename = filename = { season: nil, series: nil }.merge() @cleaner = Cleaner.new() @parser = Parser.new() @season ||= [:season] # if they passed in a default season @series ||= [:series] @file_no_ext = @filename.chomp(File.extname(@filename)) @extension = File.extname(@filename).gsub(/\./, '').downcase self.update_episode_info end |
Instance Attribute Details
#episode ⇒ Object
Returns the value of attribute episode.
9 10 11 |
# File 'lib/showfix/episode.rb', line 9 def episode @episode end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
10 11 12 |
# File 'lib/showfix/episode.rb', line 10 def extension @extension end |
#file_no_ext ⇒ Object (readonly)
Returns the value of attribute file_no_ext.
10 11 12 |
# File 'lib/showfix/episode.rb', line 10 def file_no_ext @file_no_ext end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
10 11 12 |
# File 'lib/showfix/episode.rb', line 10 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/showfix/episode.rb', line 10 def end |
#season ⇒ Object
Returns the value of attribute season.
9 10 11 |
# File 'lib/showfix/episode.rb', line 9 def season @season end |
#series ⇒ Object
Returns the value of attribute series.
9 10 11 |
# File 'lib/showfix/episode.rb', line 9 def series @series end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/showfix/episode.rb', line 9 def title @title end |
Instance Method Details
#acceptable_file? ⇒ Boolean
Determines if this is a file we should work with
43 44 45 |
# File 'lib/showfix/episode.rb', line 43 def acceptable_file? VALID_EXTENSIONS.include?(self.extension) end |
#has_episode_info? ⇒ Boolean
38 39 40 |
# 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? ⇒ Boolean
34 35 36 |
# File 'lib/showfix/episode.rb', line 34 def skip? !acceptable_file? || !has_episode_info? end |
#to_formatted_s ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
Extract info from the filename, and update fields as necessary
70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
Parse season/episode info inputted by the user from the commandline
48 49 50 51 52 |
# 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 |