Sha256: 0968c5b2c18faa0fedcdd69a188f1193a122af3637e493d78ad2bda1ca16b938

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Html2rss
  ##
  # Provides a namespace for attribute post processors.
  module AttributePostProcessors
    ##
    # Error raised when an unknown post processor name is requested.
    class UnknownPostProcessorName < Html2rss::Error; end

    ##
    # Error raised when a required option is missing.
    class MissingOption < Html2rss::Error; end

    ##
    # Error raised when an invalid type is provided.
    class InvalidType < Html2rss::Error; end

    ##
    # Maps the post processor name to the class implementing the post processor.
    #
    # The key is the name to use in the feed config.
    NAME_TO_CLASS = {
      gsub: Gsub,
      html_to_markdown: HtmlToMarkdown,
      markdown_to_html: MarkdownToHtml,
      parse_time: ParseTime,
      parse_uri: ParseUri,
      sanitize_html: SanitizeHtml,
      substring: Substring,
      template: Template
    }.freeze

    ##
    # Retrieves the attribute post processor class based on the given name.
    #
    # @param name [Symbol] The name of the post processor.
    # @return [Class] The attribute post processor class.
    # @raise [UnknownPostProcessorName] If the requested name is not found in NAME_TO_CLASS.
    def self.get_processor(name)
      NAME_TO_CLASS[name.to_sym] || raise(UnknownPostProcessorName, "Can't find a post processor named '#{name}'")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
html2rss-0.15.0 lib/html2rss/attribute_post_processors.rb
html2rss-0.14.0 lib/html2rss/attribute_post_processors.rb
html2rss-0.13.0 lib/html2rss/attribute_post_processors.rb
html2rss-0.12.0 lib/html2rss/attribute_post_processors.rb