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.
24 25 26 27 28 29 30 |
# File 'lib/movie_organizer/media.rb', line 24 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.
15 16 17 |
# File 'lib/movie_organizer/media.rb', line 15 def filename @filename end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/movie_organizer/media.rb', line 15 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/movie_organizer/media.rb', line 15 def end |
#settings ⇒ Object
Returns the value of attribute settings.
15 16 17 |
# File 'lib/movie_organizer/media.rb', line 15 def settings @settings end |
Class Method Details
.subtype(filename, options) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/movie_organizer/media.rb', line 17 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
40 41 42 43 44 45 46 47 48 |
# File 'lib/movie_organizer/media.rb', line 40 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
32 33 34 35 36 37 38 |
# File 'lib/movie_organizer/media.rb', line 32 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
50 51 52 53 |
# File 'lib/movie_organizer/media.rb', line 50 def year md = basename.match(/\((\d\d\d\d)\)|(19\d\d)|(20\d\d)/) md ? md.captures.compact.first : nil end |