Class: Episode
- Inherits:
-
Object
- Object
- Episode
- Defined in:
- lib/episode.rb
Instance Attribute Summary collapse
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#format ⇒ Object
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#path ⇒ Object
Returns the value of attribute path.
-
#season ⇒ Object
Returns the value of attribute season.
-
#srt ⇒ Object
Returns the value of attribute srt.
-
#tv_show ⇒ Object
Returns the value of attribute tv_show.
Class Method Summary collapse
Instance Method Summary collapse
- #episode_name ⇒ Object
- #episode_name_with_format ⇒ Object
- #filename ⇒ Object
- #good_format?(filename) ⇒ Boolean
-
#initialize(tv_show, path) ⇒ Episode
constructor
A new instance of Episode.
- #need_srt?(langs) ⇒ Boolean
- #srt_filename(lang) ⇒ Object
Constructor Details
#initialize(tv_show, path) ⇒ Episode
Returns a new instance of Episode.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/episode.rb', line 5 def initialize(tv_show, path) @path = path @ext = File.extname(@path) @name = File.basename(path, @ext) @tv_show = tv_show.gsub(/\s\([0-9]{4}\)/,'').chomp(' ') @srt = [] search_existing_srt define_format define_season_and_episode_number end |
Instance Attribute Details
#ext ⇒ Object
Returns the value of attribute ext.
3 4 5 |
# File 'lib/episode.rb', line 3 def ext @ext end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/episode.rb', line 3 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/episode.rb', line 3 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/episode.rb', line 3 def number @number end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/episode.rb', line 3 def path @path end |
#season ⇒ Object
Returns the value of attribute season.
3 4 5 |
# File 'lib/episode.rb', line 3 def season @season end |
#srt ⇒ Object
Returns the value of attribute srt.
3 4 5 |
# File 'lib/episode.rb', line 3 def srt @srt end |
#tv_show ⇒ Object
Returns the value of attribute tv_show.
3 4 5 |
# File 'lib/episode.rb', line 3 def tv_show @tv_show end |
Class Method Details
.valid?(filename) ⇒ Boolean
42 43 44 |
# File 'lib/episode.rb', line 42 def self.valid?(filename) filename.match(/.*(([0-9]{1,2}X[0-9]{1,2})|(S[0-9][0-9]E[0-9][0-9])).*((\.avi)|(\.mkv))$/i) end |
Instance Method Details
#episode_name ⇒ Object
21 22 23 |
# File 'lib/episode.rb', line 21 def episode_name "#{@tv_show} S#{@season < 10 ? "0#{@season}" : @season}E#{@number < 10 ? "0#{@number}" : @number}" end |
#episode_name_with_format ⇒ Object
25 26 27 |
# File 'lib/episode.rb', line 25 def episode_name_with_format episode_name + "#{format == 'hd' ? ' 720p' : ''}" end |
#filename ⇒ Object
17 18 19 |
# File 'lib/episode.rb', line 17 def filename @name + @ext end |
#good_format?(filename) ⇒ Boolean
46 47 48 49 50 51 52 53 |
# File 'lib/episode.rb', line 46 def good_format?(filename) case @format when 'hd' filename.include?('720p') || filename.include?('720') when 'sd' !filename.include?('720p') end end |
#need_srt?(langs) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/episode.rb', line 29 def need_srt?(langs) need = -1 langs = langs.reverse langs.each do |lang| need = langs.index(lang) if @srt.include?(lang) && need < langs.index(lang) end need != langs.size - 1 end |
#srt_filename(lang) ⇒ Object
38 39 40 |
# File 'lib/episode.rb', line 38 def srt_filename(lang) "#{File.dirname(path)}/#{name}.#{lang}.srt" end |