Class: ShellSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/luigi/ShellSanitizer.rb

Constant Summary collapse

REPLACE_HASH =
{
  ?“ => '"', ?” => '"', ?‘ => "'", ?’ => "'", ?„ => '"',

   => ">>",   => "<<",
   => "ae",   => "oe",    => "ue",
   => "Ae",   => "Oe",    => "Ue",
   => "ss",   => "i",     => "e",
   => "ae",   => "AE",    => "oe",
   => "OE",
  ?€ => "EUR",  => "YEN",
   => "1/2",  => "1/4",   => "3/4",
   => "(c)", ?™ => "(TM)",  => "(r)",
  ?♥ => "<3",  ?☺ => ":)"
}

Class Method Summary collapse

Class Method Details

.clean_path(path) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/luigi/ShellSanitizer.rb', line 33

def self.clean_path(path)
  path = path.strip()
  path = deumlautify path
  path.sub!(/^\./,'') # removes hidden_file_dot '.' from the begging
  path.gsub!(/\//,'_')
  path.gsub!(/\//,'_')
  return path
end

.deumlautify(string) ⇒ Object

TODO somebody find me a gem that works and I’ll replace this



26
27
28
29
30
31
# File 'lib/luigi/ShellSanitizer.rb', line 26

def self.deumlautify(string)
  string = string.dup
  REPLACE_HASH.each{|k,v| string = string.force_encoding("UTF-8").gsub k, v }
  string.each_char.to_a.keep_if {|c| c.ascii_only?}
  return string
end

.process(string) ⇒ Object



19
20
21
22
23
# File 'lib/luigi/ShellSanitizer.rb', line 19

def self.process(string)
  string = deumlautify string
  #string = Ascii.process string
  return string
end