Class: DownloadTV::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/download_tv/configuration.rb

Overview

Class used for managing the configuration of the application

Instance Method Summary collapse

Constructor Details

#initialize(user_config = {}) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
# File 'lib/download_tv/configuration.rb', line 7

def initialize(user_config = {})
  load_config(user_config)
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/download_tv/configuration.rb', line 11

def [](key)
  @content[key]
end

#[]=(key, value) ⇒ Object



15
16
17
# File 'lib/download_tv/configuration.rb', line 15

def []=(key, value)
  @content[key] = value
end

#change_configurationObject



19
20
21
22
23
# File 'lib/download_tv/configuration.rb', line 19

def change_configuration
  prompt_for_new_values
  set_default_values
  serialize
end

#clear_pendingObject



37
38
39
40
# File 'lib/download_tv/configuration.rb', line 37

def clear_pending
  self[:pending].clear
  serialize
end

#queue_pending(show) ⇒ Object



42
43
44
45
# File 'lib/download_tv/configuration.rb', line 42

def queue_pending(show)
  self[:pending] << show
  serialize
end

#serializeObject



25
26
27
28
# File 'lib/download_tv/configuration.rb', line 25

def serialize
  self[:pending] = self[:pending].uniq
  File.write(config_path, JSON.generate(@content))
end

#to_sObject



30
31
32
33
34
35
# File 'lib/download_tv/configuration.rb', line 30

def to_s
  @content.reduce('') do |mem, item|
    key, val = item
    "#{mem}#{key}: #{val}\n"
  end
end