You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: spec_slugs_helper.rb
    path of file: ./repos/archivesspace/backend/spec
    
    the code of the file until where you have to start completion: require 'pry'


def clean_slug(slug)
  if slug
    # remove all non-ASCII chars
    encoding_options = {
      :invalid           => :replace,
      :undef             => :replace,
      :replace           => '',
      :universal_newline => true
    }

    slug = slug.encode(Encoding.find('ASCII'), encoding_options)

    # if the slug contains a slash, completely zero it out.
    # this is intended to revert an entity to use the URI if the ID or name the slug was generated from is a URL.
    slug = "" if slug =~ /\//

    # downcase everything to simplify case sensitivity issues
    slug = slug.downcase

    # replace spaces with underscores
    slug = slug.gsub(" ", "_")

    # remove double hypens
    slug = slug.gsub("--", "")

    # remove single quotes
    slug = slug.gsub("'", "")

    # remove URL-reserved chars
    slug = slug.gsub(/[&;?$<>#%{}|\\^~\[\]`\/\*\(\)@=:+,!.]/, "")

    # enforce length limit of 50 chars
    slug = slug.slice(0, 50)

    # replace any multiple underscores with a single underscore
    slug = slug.gsub(/_[_]+/, "_")

    # remove any leading or trailing underscores
    slug = slug.gsub(/^_/, "").gsub(/_$/, "")

    # if slug is numeric, add a leading '__'
    # this is necessary, because numerical slugs will be interpreted as an id by the controller
    if slug.match(/^(\d)+$/)
      slug = slug.prepend
    
def clean_slug(slug)
  if slug
    # remove all non-ASCII chars
    encoding_options = {
      :invalid           => :replace,
      :undef             => :replace,
      :replace           => '',
      :universal_newline => true
    }

    slug = slug.encode(Encoding.find('ASCII'), encoding_options)

    # if the slug contains a slash, completely zero it out.
    # this is intended to revert an entity to use the URI if the ID or name the slug was generated from is a URL.
    slug = "" if slug =~ /\//

    # downcase everything to simplify case sensitivity issues
    slug = slug.downcase

    # replace spaces with underscores
    slug = slug.gsub(" ", "_")

    # remove double hypens
    slug = slug.gsub("--", "")

    # remove single quotes
    slug = slug.gsub("'", "")

    # remove URL-reserved chars
    slug = slug.gsub(/[&;?$<>#%{}|\\^~\[\]`\/\*\(\)@=:+,!.]/, "")

    # enforce length limit of 50 chars
    slug = slug.slice(0, 50)

    # replace any multiple underscores with a single underscore
    slug = slug.gsub(/_[_]+/, "_")

    # remove any leading or trailing underscores
    slug = slug.gsub(/^_/, "").gsub(/_$/, "")

    # if slug is numeric, add a leading '__'
    # this is necessary, because numerical slugs will be interpreted as an id by the controller
    if slug.match(/^(\d)+$/)
      slug = slug.prepend("__")
    end

  else
    slug = ""
  end

  return slug.parameterize
end