<commit_before>require 'backports'
require 'abstract_type'
require 'equalizer'
require 'composition'
require 'adamantium'
require 'addressable/uri'
require 'anima'

# Library namespace and abstract base class for ducktraps
class Ducktrap
  include AbstractType, Adamantium::Flat

  # Return inversed ducktrap
  #
  # @param [Object] input
  #
  # @return [Result]
  #
  # @api private
  #
  abstract_method :inverse

  # Run ducktrap on input
  #
  # @param [Object] input
  #
  # @return [Result]
  #
  # @api private
  #
  abstract_method :run

  # Register dsl name
  #
  # @param [Symbol] name
  # @param [Class:Ducktrap] ducktrap
  #
  # @return [self]
  #
  # @api private
  #
  def self.register(name)
    DSL.register(name, self)
  end
  private_class_method :register

  # Return result class
  #
  # @return [Class:Result]
  #
  # @api private
  #
  def result_klass
    self.class::Result
  end

  # Perform pretty dump of ducktrap<commit_msg>Add Ducktrap#process as easy interface<commit_after>require 'backports'
require 'abstract_type'
require 'equalizer'
require 'composition'
require 'adamantium'
require 'addressable/uri'
require 'anima'

# Library namespace and abstract base class for ducktraps
class Ducktrap
  include AbstractType, Adamantium::Flat

  class InvalidInputError < RuntimeError; end

  # Return inversed ducktrap
  #
  # @param [Object] input
  #
  # @return [Result]
  #
  # @api private
  #
  abstract_method :inverse

  # Run ducktrap on input
  #
  # @param [Object] input
  #
  # @return [Result]
  #
  # @api private
  #
  abstract_method :run

  # Process input and raise exception on error
  #
  # @param [Object] input
  #
  # @return [Object]
  #   if successful
  #
  # @raise [RuntimeError]
  #   otherwise
  #
  # @api private
  #
  def process(input)
    result = run(input)
    unless result.successful?
      raise InvalidInputError
    end
    result.output
  end

  # Register dsl name
  #
  # @param [Symbol] name
  # @param [Class:Ducktrap] ducktrap
  #
  # @return [self]
  #
  # @api private
  #
  def self.register(name)
    DSL.register(name, self)
  end
  private_class_method :register

  # Return result class
  #
  # @return [Class:Result]
  #
  # @api private
  #
  def result_klass
    self.class::Result
  end

  # Perform pretty dump of ducktrap
{'fraction_non_alphanumeric': 0.0982258762440502, 'fraction_numerical': 0.0, 'mean_word_length': 3.2112932604735884, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2705944', 'n_tokens_mistral': 814, 'n_tokens_neox': 793, 'n_words': 213}