Class: FrontMatterParser::Loader::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/front_matter_parser/loader/yaml.rb

Overview

FrontMatterParser::Loader that uses YAML library

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(whitelist_classes: []) ⇒ Yaml

Returns a new instance of Yaml.



13
14
15
# File 'lib/front_matter_parser/loader/yaml.rb', line 13

def initialize(whitelist_classes: [])
  @whitelist_classes = whitelist_classes
end

Instance Attribute Details

#whitelist_classesObject (readonly)

Classes that may be parsed by #call.



11
12
13
# File 'lib/front_matter_parser/loader/yaml.rb', line 11

def whitelist_classes
  @whitelist_classes
end

Instance Method Details

#call(string) ⇒ Hash

Loads a hash front matter from a string

Parameters:

  • string (String)

    front matter string representation

Returns:

  • (Hash)

    front matter hash representation



21
22
23
# File 'lib/front_matter_parser/loader/yaml.rb', line 21

def call(string)
  YAML.safe_load(string, whitelist_classes)
end