Class: SlateSerializer::Plain

Inherits:
Object
  • Object
show all
Defined in:
lib/slate_serializer/plain.rb

Overview

Text de- and serializer

Class Method Summary collapse

Class Method Details

.deserializer(text) ⇒ Object

Convert text to a Slate document

return [Hash] Slate document

Parameters:

  • text

    format [String] the text



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/slate_serializer/plain.rb', line 9

def deserializer(text)
  text = '' if text.nil?

  lines = split_text_into_lines(text)
  {
    document: {
      object: 'document',
      nodes: convert_lines_into_nodes(lines)
    }
  }
end

.serializer(value, options = {}) ⇒ String

Convert a Slate Document to plain text

Parameters:

  • value

    format [Hash] the Slate document

  • options (defaults to: {})

    format [Hash] options for the serializer, delimitter defaults to “n”

Returns:

  • (String)

    plain text version of the Slate documnent



26
27
28
29
30
31
# File 'lib/slate_serializer/plain.rb', line 26

def serializer(value, options = {})
  return '' unless value.key?(:document)

  options[:delimiter] = "\n" unless options.key?(:delimiter)
  serialize_node(value[:document], options)
end