Module: Slugity::Convert

Defined in:
lib/slugity/convert.rb

Class Method Summary collapse

Class Method Details

.slug(string, matcher = :default) ⇒ String

Converts the given string into a slug

Parameters:

  • string (String)

    the string to slugity

  • matcher (Symbol) (defaults to: :default)

    the matcher to use

Returns:

  • (String)

    the slug version of the provided string


9
10
11
12
13
# File 'lib/slugity/convert.rb', line 9

def self.slug string, matcher=:default
  string = Slugity::Convert.string( string, matcher ).downcase
  string.gsub!( /[^a-z0-9\-\_]/, '' )
  return string
end

.string(string, matcher = :default) ⇒ String

Converts the given string with the provided matcher

Parameters:

  • string (String)
  • matcher (Symbol) (defaults to: :default)

    the matcher to use

Returns:

  • (String)

    the converted version of the provided string


20
21
22
23
24
25
26
27
28
# File 'lib/slugity/convert.rb', line 20

def self.string string, matcher=:default
  string = Util.normalize_string( string )

  Slugity::Matchers.use(matcher).each do |match, replacement|
    string.gsub!( match, replacement )
  end

  return string
end