Class: Slideck::MetadataParser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/metadata_parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for parsing metadata in YAML format

Instance Method Summary collapse

Constructor Details

#initialize(yaml_parser, symbolize_names: nil, permitted_classes: nil) ⇒ MetadataParser

Create a MetadataParser instance

Examples:

MetadataParser.new(YAML, symbolize_names: true, permitted_classes: [])

Parameters:

  • yaml_parser (YAML)

    the YAML parser

  • symbolize_names (Boolean) (defaults to: nil)

    whether or not to symobolize names

  • permitted_classes (Array<Object>) (defaults to: nil)

    the classes allowed to be deserialized



45
46
47
48
49
# File 'lib/slideck/metadata_parser.rb', line 45

def initialize(yaml_parser, symbolize_names: nil, permitted_classes: nil)
  @yaml_parser = yaml_parser
  @symbolize_names = symbolize_names
  @permitted_classes = permitted_classes
end

Instance Method Details

#parse(content) ⇒ Hash{String, Symbol => Object}

Parse metadata from content

Examples:

parser.parse("align: center\nfooter: footer content")

Parameters:

  • content (String)

    the content to parse metadata from

Returns:

  • (Hash{String, Symbol => Object})

    the deserialized metadata



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/slideck/metadata_parser.rb', line 63

def parse(content)
  parse_method = select_parse_method
  parse_params = parse_method_params(parse_method)
  arguments = parser_arguments(parse_params)
  options = parser_options(parse_params)
   = @yaml_parser.send(parse_method, content, *arguments, **options)

  return  if symbolize_names?(options)

  @symbolize_names ? symbolize_keys() : 
end