/
options.rb
53 lines (41 loc) · 1.03 KB
/
options.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'xdg'
require 'yaml'
# Parses config options from the config file.
class Options
# Whether to show debug messages on the console.
attr_reader :debug
# An options hash for aria.
# See Aria#initialize for more info on that.
attr_reader :aria
# Mplayer options.
attr_reader :mplayer
# VLC options.
attr_reader :vlc
def initialize
opts = {
:debug => false,
:aria => {},
:mplayer => {},
:vlc => {},
}
config_file = File.join(XDG['CONFIG_HOME'].to_s, "plowui.yml")
if File.exist?(config_file)
user_opts = YAML.load_file(config_file)
opts.merge!(user_opts)
end
self.deep_to_sym(opts)
@debug = opts[:debug]
@aria = opts[:aria]
@mplayer = opts[:mplayer]
@vlc = opts[:vlc]
end
# Converts all keys to symbols in the given hash.
# Also converts nested hashes.
def deep_to_sym(hash)
hash.keys.each do |key|
value = hash.delete(key)
self.deep_to_sym(value) if value.is_a?(Hash)
hash[key.to_sym] = value
end
end
end