module ParseToHash

Constants

VERSION

Public Class Methods

parse(input) click to toggle source
# File lib/parse_to_hash.rb, line 4
def self.parse(input)
  output = []
  header = []
  input.each_line do |line|
    next if line =~ /^\s*$/
    next if line =~ /^\s*#/
    if header.empty?
      header = line.gsub(/#.*$/m, '').gsub(/\s+/m, ' ').strip.split(' ').map { |i| i.to_sym }
    else
      output << Hash[header.zip(line.gsub(/#.*$/m, '').gsub(/\s+/m, ' ').strip.split(' '))]
    end
  end
  output
end