Class: Mbrao::ParsingEngines::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mbrao/parsing_engines/base.rb

Overview

A base class for all parsers.

Direct Known Subclasses

PlainText

Instance Method Summary collapse

Instance Method Details

#filter_content(_content, _locales = [], _options = {}) ⇒ String|HashWithIndifferentAccess

Filters content of a post by locale.

Parameters:

  • _content (Content)

    The content to filter.

  • _locales (String|Array) (defaults to: [])

    The desired locales. Can include * to match all.

  • _options (Hash) (defaults to: {})

    Options to customize parsing.

Returns:

  • (String|HashWithIndifferentAccess)

    Return the filtered content in the desired locales. If only one locale is required, then a String is returned, else a HashWithIndifferentAccess with locales as keys.

Raises:



37
38
39
# File 'lib/mbrao/parsing_engines/base.rb', line 37

def filter_content(_content, _locales = [], _options = {})
  raise Mbrao::Exceptions::Unimplemented.new
end

#parse(content, options = {}) ⇒ Object

Parses a content and return a Content object.

Parameters:

  • content (Object)

    The content to parse.

  • options (Hash) (defaults to: {})

    Options to customize parsing.



45
46
47
48
49
# File 'lib/mbrao/parsing_engines/base.rb', line 45

def parse(content, options = {})
  , body = separate_components(content, options)
   = (, options)
  Mbrao::Content.create(, body)
end

#parse_metadata(_content, _options = {}) ⇒ Hash

Parses metadata part and returns all valid metadata.

Parameters:

  • _content (Object)

    The content to parse.

  • _options (Hash) (defaults to: {})

    Options to customize parsing.

Returns:

  • (Hash)

    All valid metadata for the content.

Raises:



26
27
28
# File 'lib/mbrao/parsing_engines/base.rb', line 26

def (_content, _options = {})
  raise Mbrao::Exceptions::Unimplemented.new
end

#separate_components(_content, _options = {}) ⇒ Array

Parses a whole post content and return its metadata and content parts.

Parameters:

  • _content (Object)

    The content to parse.

  • _options (Hash) (defaults to: {})

    Options to customize parsing.

Returns:

  • (Array)

    An array of metadata and contents parts.

Raises:



17
18
19
# File 'lib/mbrao/parsing_engines/base.rb', line 17

def separate_components(_content, _options = {})
  raise Mbrao::Exceptions::Unimplemented.new
end