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


46
47
48
# File 'lib/safe_string.rb', line 46

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

#codeizeObject


62
63
64
# File 'lib/safe_string.rb', line 62

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

#dig(depth = 1) ⇒ Object


8
9
10
# File 'lib/safe_string.rb', line 8

def dig(depth = 1)
  strip.indent(depth) + "\n"
end

#indent(depth = 1) ⇒ Object


12
13
14
# File 'lib/safe_string.rb', line 12

def indent(depth = 1)
  gsub(/^/, '  ' * depth)
end

#lowerObject


26
27
28
# File 'lib/safe_string.rb', line 26

def lower
  dup.lower!
end

#lower!Object


30
31
32
33
34
# File 'lib/safe_string.rb', line 30

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

#lower_asciiObject


54
55
56
# File 'lib/safe_string.rb', line 54

def lower_ascii
  ascii.downcase
end

#simpleizeObject


58
59
60
# File 'lib/safe_string.rb', line 58

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

#translate(from, to) ⇒ Object


16
17
18
# File 'lib/safe_string.rb', line 16

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

#translate!(from, to) ⇒ Object


20
21
22
23
24
# File 'lib/safe_string.rb', line 20

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


36
37
38
# File 'lib/safe_string.rb', line 36

def upper
  dup.upper!
end

#upper!Object


40
41
42
43
44
# File 'lib/safe_string.rb', line 40

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

#upper_asciiObject


50
51
52
# File 'lib/safe_string.rb', line 50

def upper_ascii
  ascii.upcase
end