Class: String

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

Constant Summary collapse

ACCENTS_MAPPING =
[
  {letter: 'A', upcase: 'ÁÀÄÂ', downcase: 'áàäâ'},
  {letter: 'E', upcase: 'ÉÈËÊ', downcase: 'éèëê'},
  {letter: 'I', upcase: 'ÍÌÏÎ', downcase: 'íìïî'},
  {letter: 'O', upcase: 'ÓÒÖÔ', downcase: 'óòöô'},
  {letter: 'U', upcase: 'ÚÙÜÛ', downcase: 'úùüû'}
]

Instance Method Summary collapse

Instance Method Details

#downcaseObject



28
29
30
# File 'lib/core_extended/string.rb', line 28

def downcase
  self.dup.downcase!
end

#downcase!Object



23
24
25
26
# File 'lib/core_extended/string.rb', line 23

def downcase!
  ACCENTS_MAPPING.each { |map| tr! map[:upcase], map[:downcase] }
  downcase_ignoring_accents! || self
end

#downcase_ignoring_accents!Object



22
# File 'lib/core_extended/string.rb', line 22

alias_method :downcase_ignoring_accents!, :downcase!

#normalizedObject



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

def normalized
  self.dup.normalized!
end

#normalized!Object



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

def normalized!
  self.unaccented!.downcase!
end

#unaccentedObject



40
41
42
# File 'lib/core_extended/string.rb', line 40

def unaccented
  self.dup.unaccented!
end

#unaccented!Object



32
33
34
35
36
37
38
# File 'lib/core_extended/string.rb', line 32

def unaccented!
  ACCENTS_MAPPING.each do |map|
    tr! map[:upcase], map[:letter]
    tr! map[:downcase], map[:letter].downcase
  end
  self
end

#upcaseObject



18
19
20
# File 'lib/core_extended/string.rb', line 18

def upcase
  self.dup.upcase!
end

#upcase!Object



13
14
15
16
# File 'lib/core_extended/string.rb', line 13

def upcase!
  ACCENTS_MAPPING.each { |map| tr! map[:downcase], map[:upcase] }
  upcase_ignoring_accents! || self
end

#upcase_ignoring_accents!Object



12
# File 'lib/core_extended/string.rb', line 12

alias_method :upcase_ignoring_accents!, :upcase!