Class: Structura::Cfg
- Inherits:
-
Object
- Object
- Structura::Cfg
- Includes:
- Singleton
- Defined in:
- lib/structura/cfg.rb
Instance Method Summary collapse
- #is_string(target) ⇒ Object
- #load_file(file_path) ⇒ Object
- #read_value(section, variable) ⇒ Object
- #string_to_symbol(string) ⇒ Object
Instance Method Details
#is_string(target) ⇒ Object
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
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 |