Module: Zonify::YAML

Extended by:
YAML
Included in:
YAML
Defined in:
lib/zonify.rb

Instance Method Summary collapse

Instance Method Details

#format(records, suffix = '') ⇒ Object



459
460
461
462
463
464
465
466
# File 'lib/zonify.rb', line 459

def format(records, suffix='')
 _suffix_ = Zonify._dot(Zonify.dot_(suffix))
 entries = records.keys.sort.map do |k|
   dumped = ::YAML.dump(k=>records[k])
   Zonify::YAML.trim_lines(dumped).map{|ln| '  ' + ln }.join
 end.join
 "suffix: #{_suffix_}\nrecords:\n" + entries
end

#read(text) ⇒ Object



467
468
469
470
471
472
# File 'lib/zonify.rb', line 467

def read(text)
  yaml = ::YAML.load(text)
  if yaml['suffix'] and yaml['records']
    [yaml['suffix'], yaml['records']]
  end
end

#trim_lines(yaml) ⇒ Object



473
474
475
476
477
478
# File 'lib/zonify.rb', line 473

def trim_lines(yaml)
 lines = yaml.lines.to_a
 lines.shift if /^---/.match(lines[0])
 lines.pop if /^$/.match(lines[-1])
 lines
end