Class: Dictuby::DictubyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/dictuby/config.rb

Instance Method Summary collapse

Constructor Details

#initializeDictubyConfig

Returns a new instance of DictubyConfig.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dictuby/config.rb', line 4

def initialize
    @default_dict = 'en-sk'
    @config_path = File.expand_path('~') + '/.dictuby'
    @settings = nil

    if File.exists?(@config_path)
        File.open(@config_path, 'r') do |content|
            @settings = YAML.load(content)
        end
    end

    if !@settings
        @settings = {}
        set('dictionary', @default_dict)
    end
end

Instance Method Details

#get(key) ⇒ Object



21
22
23
# File 'lib/dictuby/config.rb', line 21

def get(key)
    @settings[key]
end

#saveObject



30
31
32
33
34
# File 'lib/dictuby/config.rb', line 30

def save
    f = File.new(@config_path, 'w')
    f.write(YAML.dump(@settings))
    f.close
end

#set(key, value) ⇒ Object



25
26
27
28
# File 'lib/dictuby/config.rb', line 25

def set(key, value)
    @settings[key] = value
    save
end