Class: Structura::Cfg

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/structura/cfg.rb

Instance Method Summary collapse

Instance Method Details

#is_string(target) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
# File 'lib/structura/cfg.rb', line 29

def is_string target
  raise ArgumentError, "Expected String Parameter: #{target}" if !target.instance_of? String
end

#load_file(file_path) ⇒ Object



20
21
22
23
# File 'lib/structura/cfg.rb', line 20

def load_file file_path
  raw_config = File.read(file_path)
  @cfg = YAML.load(raw_config)
end

#read_value(section, variable) ⇒ Object

Raises:

  • (LoadError)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/structura/cfg.rb', line 8

def read_value section, variable
  raise LoadError, 'Configuration file has not been loaded' if !@cfg

  is_string section
  is_string variable

  return false if !@cfg.include? section
  return false if !@cfg[section].include? string_to_symbol(variable)

  @cfg[section][string_to_symbol(variable)]
end

#string_to_symbol(string) ⇒ Object



25
26
27
# File 'lib/structura/cfg.rb', line 25

def string_to_symbol string
  string.to_s.downcase.gsub(/\s+/, "_").to_sym
end