Module: Verso::Sluggable Abstract

Included in:
Cluster, Occupation, Pathway, ProgramArea
Defined in:
lib/verso/sluggable.rb

Overview

This module is abstract.

Implement a title method that returns a string.

Mixin for class, providing a slug method that returns a parameterized version of the title, a la ActiveSupport::Inflector’s String#parameterize.

Instance Method Summary collapse

Instance Method Details

#slugString

Returns Parameterized title.

Returns:

  • (String)

    Parameterized title



8
9
10
11
12
13
14
15
16
# File 'lib/verso/sluggable.rb', line 8

def slug
  # swiped from ActiveSupport::Inflector
  parameterized_string = title.dup
  parameterized_string.gsub!(/[^a-z0-9\-_]+/i, '-')
  re_sep = Regexp.escape('-')
  parameterized_string.gsub!(/#{re_sep}{2,}/, '-')
  parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
  parameterized_string.downcase
end