Sha256: 7b538c2e37f0f1d107884d3b9a141b2ef762b511d58215fae8dfbad7a810c89c
Contents?: true
Size: 787 Bytes
Versions: 1
Compression:
Stored size: 787 Bytes
Contents
module ANVL def self.parse str data = {} entries = [] lines = str.split("\n") lines.each do |l| case l when /^\#/ # comment next when /^\s/ entries.last << l.gsub(/^\s+/, ' ') else entries << l end end entries.each do |e| key, value = e.split ":", 2 data[key.to_sym] ||= [] data[key.to_sym] << value.strip end data.each do |key, value| data[key] = value.first if value.length == 1 end data end def self.to_anvl h lines = [] h.each do |key, value| if value.respond_to? :each value.each do |v| lines << "#{key}: #{v}" end else lines << "#{key}: #{value}" end end lines.join "\n" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
anvl-0.1.0 | lib/anvl.rb |