Skip to content

Instantly share code, notes, and snippets.

@kibitzk
Created October 21, 2016 20:42
Show Gist options
  • Save kibitzk/52cc693c5588ff774758fa3842c9a5de to your computer and use it in GitHub Desktop.
Save kibitzk/52cc693c5588ff774758fa3842c9a5de to your computer and use it in GitHub Desktop.
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