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
63 @enabled_sources.each
do |source
|
65 current_track
= source
.current_track
67 # This is a special thing for arguments. The thing is, they need to
68 # be inputted manually. So, if they are present they won't allow
69 # anyone else to give results. Makes sense, yet a bit hacky.
70 unless current_track
[:artist].nil? || current_track
[:artist].empty
? || current_track
[:song].nil? || current_track
[:song].empty
?
71 track
= current_track
unless lock
72 lock
= true if source
.class.name
== "arguments"
75 raise SourceConfigurationException
81 def available_sources(format
= false)
82 path_root
= File
.expand_path(File
.dirname(__FILE__
))
83 sources
= Dir
[path_root+
"/sources/*.rb"].map
{ |s
|
84 name
= s
.split("/").last
.gsub(/\
.rb
/, "")
86 # Add a star to denote enabled sources
90 # Remove arguments (Hack?) We don't want anybody to touch tihs one.
91 sources
.delete("arguments")
93 format_sources(sources
)
99 def format_sources(sources
)
101 s
<< "*" if @config["enabled_sources"].include?(s
)