Class: Slideck::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/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 extracting metadata and slides from content

Instance Method Summary collapse

Constructor Details

#initialize(string_scanner, metadata_parser) ⇒ Parser

Create a Parser instance

Examples:

Parser.new(StringScanner, Slideck::MetadataParser)

Parameters:

  • string_scanner (StringScanner)

    the content scanner

  • metadata_parser (Slideck::MetadataParser)

    the metadata parser



43
44
45
46
# File 'lib/slideck/parser.rb', line 43

def initialize(string_scanner, )
  @string_scanner = string_scanner
  @metadata_parser = 
end

Instance Method Details

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

Parse metadata and slides from content

Examples:

parser.parse("align: center\n---\nSlide1\n---\nSlide2\n---")

Parameters:

  • content (String)

    the content to parse slides from

Returns:

  • (Hash{Symbol => Hash, Array<String>})

    the metadata and slides content



60
61
62
63
64
65
66
# File 'lib/slideck/parser.rb', line 60

def parse(content)
  scanner = @string_scanner.new(content)
  slides = split_into_slides(scanner)
   = (slides.first && slides.first[:content])

  {metadata: , slides: .empty? ? slides : slides[1..-1]}
end