Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/speaking_url/core_ext/string/inflections.rb

Instance Method Summary collapse

Instance Method Details

#downcaseObject



16
17
18
19
20
21
22
23
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 16

def downcase
  translations = [ ["Ä", "ä"], ["Ö", "ö"], ["Ü", "ü"] ]
  res = self.original_downcase
  translations.each do |f,t|
    res.gsub!(f,t)
  end
  res
end

#original_downcaseObject



4
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 4

alias_method :original_downcase, :downcase

#original_upcaseObject



5
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 5

alias_method :original_upcase, :upcase

#unumlautObject

Romanizes all German Umlaut characters

"Füße".unumlaut # => "Fuesse"


36
37
38
39
40
41
42
43
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 36

def unumlaut
  res = self
  translations = [ ["Ä", "AE"], ["ä", "ae"], ["Ö", "OE"], ["ö", "oe"], ["Ü", "UE"], ["ü", "ue"], ["ß", "ss"] ]
  translations.each do |f,t|
    res.gsub!(f,t)
  end
  res
end

#upcaseObject



7
8
9
10
11
12
13
14
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 7

def upcase
  translations = [ ["ä", "Ä"], ["ö", "Ö"], ["ü", "Ü"], ["ß", "SS"] ]
  res = self.original_upcase
  translations.each do |f,t|
    res.gsub!(f,t)
  end
  res
end

#urlifyObject

Replaces all white space and special characters of a String with dashes, to make it a valid url segment:

"** Dr. Jekyll and Mr. Hyde ++" # => "Dr-Jekyll-and-Mr-Hyde"


29
30
31
# File 'lib/speaking_url/core_ext/string/inflections.rb', line 29

def urlify
  self.split(/\W+/).reject(&:blank?).join('-')
end