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.



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

def convert_to_humanized_name(name, suffix)
  name.gsub(/\.#{::Regexp.quote(suffix)}$/i, '').gsub(/_/, ' ').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.



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

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