Module: Alchemy::NameConversions

Included in:
Attachment, Page::PageNaming, Picture
Defined in:
lib/alchemy/name_conversions.rb

Overview

Provides methods for converting names into urlnames and vice versa.

Instance Method Summary collapse

Instance Method Details

#convert_to_humanized_name(name, suffix) ⇒ Object

Converts a filename and suffix into a human readable name.



22
23
24
# File 'lib/alchemy/name_conversions.rb', line 22

def convert_to_humanized_name(name, suffix)
  name.gsub(/\.#{::Regexp.quote(suffix)}$/i, '').tr('_', ' ').strip
end

#convert_to_urlname(name) ⇒ Object

Converts a given name into url save and readable urlanme. Uses rails parameterize, but converts german umlauts before.



11
12
13
14
15
16
17
18
# File 'lib/alchemy/name_conversions.rb', line 11

def convert_to_urlname(name)
  name
    .gsub(/[äÄ]/, 'ae')
    .gsub(/[üÜ]/, 'ue')
    .gsub(/[öÖ]/, 'oe')
    .gsub(/[ß]/, 'ss')
    .parameterize
end