Class: Coradoc::Serializer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/serializer/registry.rb

Overview

Base class for element serializers

Provides a common interface for all serializers. Subclasses should implement #serialize method.

Examples:

Creating a custom serializer

class MyElementSerializer < Coradoc::Serializer::Base
  def serialize(element, format: :adoc, **options)
    "Custom: #{element.text}"
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.serialize(element, **options) ⇒ Object

Class method for serialization



147
148
149
# File 'lib/coradoc/serializer/registry.rb', line 147

def self.serialize(element, **options)
  new.serialize(element, **options)
end

Instance Method Details

#serialize(element, format: :adoc, **_options) ⇒ String

Serialize an element to the target format

Parameters:

  • element (Object)

    The element to serialize

  • format (Symbol) (defaults to: :adoc)

    The output format

  • options (Hash)

    Additional options

Returns:

  • (String)

    The serialized output



142
143
144
# File 'lib/coradoc/serializer/registry.rb', line 142

def serialize(element, format: :adoc, **_options)
  element.to_s
end