Class: MovieOrganizer::Organizer

Inherits:
Object
  • Object
show all
Defined in:
lib/movie_organizer/organizer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOrganizer

Returns a new instance of Organizer.



16
17
18
# File 'lib/movie_organizer/organizer.rb', line 16

def initialize
  @logger = Logger.instance
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/movie_organizer/organizer.rb', line 9

def logger
  @logger
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/movie_organizer/organizer.rb', line 9

def options
  @options
end

Class Method Details

.instanceObject

Make a singleton but allow the class to be instantiated for easier testing



12
13
14
# File 'lib/movie_organizer/organizer.rb', line 12

def self.instance
  @instance || new
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/movie_organizer/organizer.rb', line 20

def start
  start_time = Time.now
  @options = collect_args
  logger.info('Starting MovieOrganizer...'.green)
  count = 0

  # Enumerate all of the new source media
  @media_list = MediaList.new(MovieOrganizer.source_directories)

  # Process each source file
  @media_list.file_collection.each do |file|
    # Get movie or TV show information so we can rename the file if necessary
    media = Media.subtype(file, options)
    # Move and/or rename the file
    logger.info("Processing [#{file}] - #{media.class.to_s.yellow}")
    media.process!
    count += 1
  end
  elapsed = Time.now - start_time
  logger.info("Processed #{count} vidoes in [#{elapsed}] seconds.".yellow)
end