8 @config = Configuration
.instance
9 @config["enabled_sources"].each
do |source
|
10 if klass
= parse_class(camelize(source
))
11 current_source
= klass
.new
12 @enabled_sources << current_source
14 raise StartSourceException
19 def enable(source_name
)
20 if available_sources
.include?(source_name
)
21 if klass
= parse_class(camelize(source_name
))
23 @config["enabled_sources"] << klass
.name
24 @config["enabled_sources"].uniq!
27 raise EnableSourceException
34 def disable(source_name
)
35 if available_sources
.include?(source_name
)
36 if klass
= parse_class(camelize(source_name
))
37 @config["enabled_sources"].delete(klass
.name
)
40 raise DisableSourceException
47 def reset(source_name
)
48 if available_sources
.include?(source_name
)
49 if klass
= parse_class(camelize(source_name
))
53 raise ResetSourceException
62 @enabled_sources.each
do |source
|
64 current_track
= source
.current_track
66 unless current_track
[:artist].nil? || current_track
[:artist].empty
? || current_track
[:song].nil? || current_track
[:song].empty
?
70 raise SourceConfigurationException
76 def available_sources(format
= false)
77 path_root
= File
.expand_path(File
.dirname(__FILE__
))
78 sources
= Dir
[path_root+
"/sources/*"].map
{ |s
|
79 name
= s
.split("/").last
.gsub(/\
.rb
/, "")
81 # Add a star to denote enabled sources
85 # Remove arguments (Hack?) We don't want anybody to touch tihs one.
86 sources
.delete("arguments")
88 format_sources(sources
)
94 def format_sources(sources
)
96 s
<< "*" if @config["enabled_sources"].include?(s
)