Module: Agave::Dump::Format::Yaml

Defined in:
lib/agave/dump/format/yaml.rb

Class Method Summary collapse

Class Method Details

.deep_hashify_items(value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/agave/dump/format/yaml.rb', line 25

def self.deep_hashify_items(value)
  case value
  when Array
    value.map { |v| deep_hashify_items(v) }
  when Hash
    value.each_with_object({}) do |(k, v), acc|
      acc[k] = deep_hashify_items(v)
    end
  when ::Agave::Local::Item
    value.to_hash
  else
    if value.respond_to?(:to_hash)
      value.to_hash
    else
      value
    end
  end
end

.dump(value) ⇒ Object



44
45
46
47
# File 'lib/agave/dump/format/yaml.rb', line 44

def self.dump(value)
  plain = deep_hashify_items(value)
  YAML.dump(plain.deep_stringify_keys).chomp.gsub(/^\-+\n/, '')
end

.frontmatter_dump(value) ⇒ Object



49
50
51
# File 'lib/agave/dump/format/yaml.rb', line 49

def self.frontmatter_dump(value)
  "---\n#{dump(value)}\n---"
end