Class: Buildhosts::ConfigParser
- Inherits:
-
Object
- Object
- Buildhosts::ConfigParser
- Defined in:
- lib/buildhosts/ConfigParser.rb
Class Method Summary collapse
Class Method Details
.parse(file) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/buildhosts/ConfigParser.rb', line 3 def self.parse file if !File.exists? file puts "Error: File does not exist." return false end conf = Hash.new last_key = String.new raw = File.open(file, "r") raw.each_line do |line| match = line.match(/\[(\w*)\]/) if !match.nil? key = match.to_a[1..-1][0] conf [key] = Array.new last_key = key else conf[last_key] << line.strip if (!line.strip.empty?) end end raw.close return conf end |