Class: String

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

Constant Summary collapse

MAJUSCULES =
%w(Á À Â Ä Å Ã Æ É È Ê Ë Ì Ï Î Ò Ô Ö Œ Û Ü Ù Ç).freeze
MINUSCULES =
%w(á à â ä å ã æ é è ê ë ì ï î ò ô ö œ û ü ù ç).freeze
MOLUSCULES =

Phonétique

%w(a a a a a a ae é é é é i i i o o o oe u u u ss).freeze
MEJUSCULES =

Simplification “lisible”

%w(A A A A A A AE E E E E I I I O O O OE U U U C).freeze
%w(a a a a a a ae e e e e i i i o o o oe u u u c).freeze

Instance Method Summary collapse

Instance Method Details

#asciiObject


44
45
46
# File 'lib/safe_string.rb', line 44

def ascii
  translate(MINUSCULES, MENUSCULES).translate(MAJUSCULES, MEJUSCULES)
end

#codeizeObject


60
61
62
# File 'lib/safe_string.rb', line 60

def codeize
  upper_ascii.gsub(/[^A-Z0-9]/, '')
end

#dig(depth = 1) ⇒ Object


10
11
12
# File 'lib/safe_string.rb', line 10

def dig(depth = 1)
  strip.gsub(/^/, '  ' * depth) + "\n"
end

#lowerObject


24
25
26
# File 'lib/safe_string.rb', line 24

def lower
  dup.lower!
end

#lower!Object


28
29
30
31
32
# File 'lib/safe_string.rb', line 28

def lower!
  translate!(MAJUSCULES, MINUSCULES)
  downcase!
  self
end

#lower_asciiObject


52
53
54
# File 'lib/safe_string.rb', line 52

def lower_ascii
  ascii.downcase
end

#simpleizeObject


56
57
58
# File 'lib/safe_string.rb', line 56

def simpleize
  ascii.gsub(/[^a-zA-Z0-9\_]/, '_').squeeze('_')
end

#translate(from, to) ⇒ Object


14
15
16
# File 'lib/safe_string.rb', line 14

def translate(from, to)
  dup.translate!(from, to)
end

#translate!(from, to) ⇒ Object


18
19
20
21
22
# File 'lib/safe_string.rb', line 18

def translate!(from, to)
  force_encoding('UTF-8') if respond_to? :force_encoding
  from.length.times { |x| gsub!(from[x], to[x]) }
  self
end

#upperObject


34
35
36
# File 'lib/safe_string.rb', line 34

def upper
  dup.upper!
end

#upper!Object


38
39
40
41
42
# File 'lib/safe_string.rb', line 38

def upper!
  translate!(MINUSCULES, MAJUSCULES)
  upcase!
  self
end

#upper_asciiObject


48
49
50
# File 'lib/safe_string.rb', line 48

def upper_ascii
  ascii.upcase
end