Class: FlatHash::Serialiser
Instance Method Summary collapse
Instance Method Details
#read(io) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flat_hash/serialiser.rb', line 6 def read io hash = {} first = true key, value = nil, '' io.each do |line| line.chomp! return read_as_yaml(io, line) if first and line =~ /^--- / first = false if key if line == '<----->' hash[key] = value key, value = nil, '' else value << "\n" if value.length > 0 value << line end else key = line end end hash[key] = value if key hash end |
#write(io, hash) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/flat_hash/serialiser.rb', line 30 def write io, hash first = true hash.keys.sort.each do |key| io.puts '<----->' unless first io.puts key io.puts hash[key] first = false end end |