Module: ParseToHash
- Defined in:
- lib/parse_to_hash.rb,
lib/parse_to_hash/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.parse(input) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 |