Class: Markbridge::Parsers::TextFormatter::Handlers::BaseHandler Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/parsers/text_formatter/handlers/base_handler.rb

Overview

This class is abstract.

Subclass and override #process to implement a custom handler

Base class for TextFormatter XML element handlers

Handlers process s9e/TextFormatter XML elements and convert them to AST nodes. Each handler implements the process method to handle a specific element type.

Instance Method Summary collapse

Instance Method Details

#element_classClass

The AST element class this handler creates Used for introspection and documentation

Returns:

  • (Class)

    the AST node class

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/markbridge/parsers/text_formatter/handlers/base_handler.rb', line 27

def element_class
  raise NotImplementedError, "#{self.class} must implement #element_class"
end

#process(element:, parent:) ⇒ AST::Element?

Process an XML element and convert it to AST node(s)

Parameters:

  • element (Nokogiri::XML::Element)

    the XML element to process

  • parent (AST::Element)

    the parent AST node to add children to

Returns:

  • (AST::Element, nil)

    the created element if children should be processed, nil otherwise

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/markbridge/parsers/text_formatter/handlers/base_handler.rb', line 19

def process(element:, parent:)
  raise NotImplementedError, "#{self.class} must implement #process"
end