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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = nil) ⇒ Config

Returns a new instance of Config.



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

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#locationObject

Returns the value of attribute location.



11
12
13
# File 'lib/minder/config.rb', line 11

def location
  @location
end

Instance Method Details

#loadObject



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

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