Module: GSuper::Settings
- Defined in:
- lib/gsuper/settings.rb
Class Method Summary collapse
Class Method Details
.default ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gsuper/settings.rb', line 7 def default { "font" => "Sans Bold 24", "super-x" => 0, "super-y" => 0, "super-width" => 640, "super-height" => 480, "text" => "", "text-color" => [1.0, 0.5, 0.0], "shadow-color" => [0.0, 0.0, 1.0], } end |
.filepath ⇒ Object
21 22 23 |
# File 'lib/gsuper/settings.rb', line 21 def filepath ENV['HOME'] + '/.config/gsuper/settings.tml' end |
.load ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gsuper/settings.rb', line 26 def load begin user = TOML.load_file(filepath) rescue Errno::ENOENT # 設定ファイルが見付からないが、別に構わない user = {} rescue TOML::ParseError => e STDERR.puts "Error: corrupt settings file, ignoring" STDERR.puts e user = {} end return default.merge(user) end |
.save(settings) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/gsuper/settings.rb', line 41 def save(settings) difference = (settings.to_a - default.to_a).to_h toml = TOML.dump(difference) FileUtils.mkdir_p(File.dirname(filepath)) File.open(filepath, "w") do |f| f.write(toml) end end |