Created
October 21, 2016 20:42
-
-
Save kibitzk/52cc693c5588ff774758fa3842c9a5de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.parse_config(file) | |
config = {} | |
File.open(file).each_line do |line| | |
line.strip! | |
# skip comments | |
next if /^\#/.match(line) | |
# skip empty lines | |
next if /^\s*$/.match(line) | |
if(/^\[(.+?)\]/.match(line)) | |
@group = $1.to_sym | |
config[@group] = Array.new | |
next | |
end | |
if /^([\w\d\_\-]+)\s*(=*)\s*([\w\d:\_\/\.\-]*)$/.match(line) | |
param, value = $1, $3 | |
# if there was no value in line, value should be set to true | |
value = true if value.empty? | |
config[@group] << [param, value] | |
end | |
end | |
config | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment