Class: MovieOrganizer::Media
- Inherits:
-
Object
- Object
- MovieOrganizer::Media
- Defined in:
- lib/movie_organizer/media.rb
Overview
This meta-class factory accepts the media filename, and from that determines if it is likely to be:
-
a TV show
-
a Movie
-
a home video or other type
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
-
#settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename, options) ⇒ Media
constructor
A new instance of Media.
- #movie? ⇒ Boolean
- #tv_show? ⇒ Boolean
- #year ⇒ Object
Constructor Details
#initialize(filename, options) ⇒ Media
Returns a new instance of Media.
23 24 25 26 27 28 29 |
# File 'lib/movie_organizer/media.rb', line 23 def initialize(filename, ) @filename = filename = @tv_show = nil @logger = Logger.instance @settings = Settings.new end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
14 15 16 |
# File 'lib/movie_organizer/media.rb', line 14 def filename @filename end |
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/movie_organizer/media.rb', line 14 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/movie_organizer/media.rb', line 14 def end |
#settings ⇒ Object
Returns the value of attribute settings.
14 15 16 |
# File 'lib/movie_organizer/media.rb', line 14 def settings @settings end |
Class Method Details
.subtype(filename, options) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/movie_organizer/media.rb', line 16 def self.subtype(filename, ) instance = new(filename, ) return TvShow.new(filename, ) if instance.tv_show? return Movie.new(filename, ) if instance.movie? Video.new(filename, ) end |
Instance Method Details
#movie? ⇒ Boolean
39 40 41 42 43 44 45 46 47 |
# File 'lib/movie_organizer/media.rb', line 39 def movie? return @movie unless @movie.nil? @movie = false Tmdb::Api.key(settings[:movies][:tmdb_key]) title = sanitize(File.basename(filename, ext)).gsub(/\d\d\d\d/, '').strip matches = Tmdb::Movie.find(title) @movie = matches.any? @movie end |
#tv_show? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/movie_organizer/media.rb', line 31 def tv_show? return @tv_show unless @tv_show.nil? @tv_show = false @tv_show = true unless filename.match(/S\d+E\d+/i).nil? @tv_show = true unless filename.match(/\d+x\d+/i).nil? @tv_show end |
#year ⇒ Object
49 50 51 52 |
# File 'lib/movie_organizer/media.rb', line 49 def year md = basename.match(/\((\d\d\d\d)\)|(19\d\d)|(20\d\d)/) md ? md.captures.compact.first : nil end |