Class: Tagomatic::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/tagomatic/main.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Main

Returns a new instance of Main.



38
39
40
# File 'lib/tagomatic/main.rb', line 38

def initialize(configuration)
  @configuration = configuration
end

Class Method Details

.run!(*arguments) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tagomatic/main.rb', line 16

def self.run!(*arguments)
  configuration = Tagomatic::SystemConfiguration.new do
    register :options => Tagomatic::Options.new
    register :parser => Tagomatic::OptionsParser.new(get_options)
    register :local_options_matcher_factory => Tagomatic::ObjectFactory.new
    register :logger => Tagomatic::Logger.new(get_options)
    register :scanner => Tagomatic::Scanner.new(get_options, get_parser, get_local_options_matcher_factory, get_logger)
    register :format_matcher_factory => Tagomatic::ObjectFactory.new
    register :tags_processor_factory => Tagomatic::ObjectFactory.new
    register :tags_processor_chain => Tagomatic::TagsProcessingChain.new(get_options, get_tags_processor_factory, get_logger)
    register :compiler => Tagomatic::FormatCompiler.new(get_format_matcher_factory, get_logger)
    register :mp3info => Tagomatic::Mp3InfoWrapper.new
    register :info_updater_factory => Tagomatic::ObjectFactory.new
    register :tagger => Tagomatic::Tagger.new(get_options, get_compiler, get_tags_processor_chain, get_mp3info, get_info_updater_factory, get_logger)
  end

  parser = configuration[:parser]
  parser.parse!(arguments)

  new(configuration).run!
end

Instance Method Details

#run!Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tagomatic/main.rb', line 42

def run!
  options = @configuration[:options]

  show_usage_and_exit if options[:files].empty?

  scanner = @configuration[:scanner]
  tagger = @configuration[:tagger]

  files = options[:files]
  files.each do |file|
    scanner.process!(nil, file) do |mp3filepath|
      tagger.process!(mp3filepath)
    end
  end
end

#show_usage_and_exitObject



58
59
60
61
# File 'lib/tagomatic/main.rb', line 58

def show_usage_and_exit
  puts @configuration[:parser].show_help
  exit 1
end