Class: Minder::Config

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

Constant Summary collapse

DEFAULTS =
{
  work_duration: 25,
  short_break_duration: 5,
  long_break_duration: 15,
  emoji: 'tomato',
  database_name: 'database'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = nil) ⇒ Config

Returns a new instance of Config.



16
17
18
19
# File 'lib/minder/config.rb', line 16

def initialize(location = nil)
  self.location = location
  @data = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/minder/config.rb', line 14

def data
  @data
end

#locationObject

Returns the value of attribute location.



13
14
15
# File 'lib/minder/config.rb', line 13

def location
  @location
end

Instance Method Details

#loadObject



21
22
23
24
25
26
27
28
29
# File 'lib/minder/config.rb', line 21

def load
  if File.exists?(location.to_s)
    file = File.open(location, 'r')
    @data = JSON.parse(file.read, symbolize_names: true)
  end
  DEFAULTS.each do |key, value|
    data[key] ||= DEFAULTS[key]
  end
end