class String

Constants

ACCENTS_MAPPING
CASE_EXTENSION
SIMILAR_CHARACTER_MAPPING

Public Instance Methods

camelize(upper_case_first_letter=true) click to toggle source
# File lib/core_extended/string.rb, line 74
def camelize(upper_case_first_letter=true)
  return self if self !~ /_/ && self =~ /[A-Z]+.*/
  if upper_case_first_letter
    split('_').map{|e| e.capitalize}.join
  else
    split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
  end
end
downcase() click to toggle source
# File lib/core_extended/string.rb, line 25
def downcase
  self.dup.tap(&:downcase!)
end
downcase!() click to toggle source
# File lib/core_extended/string.rb, line 19
def downcase!
  ACCENTS_MAPPING.values.each { |map| tr! map['upcase'], map['downcase'] }
  tr! CASE_EXTENSION['upcase'], CASE_EXTENSION['downcase']
  downcase_ignoring_accents!
end
Also aliased as: downcase_ignoring_accents!
downcase_ignoring_accents!()
Alias for: downcase!
letterize() click to toggle source
# File lib/core_extended/string.rb, line 47
def letterize
  self.dup.tap(&:letterize!)
end
letterize!() click to toggle source
# File lib/core_extended/string.rb, line 41
def letterize!
  SIMILAR_CHARACTER_MAPPING.each do |letter, similar_chars|
    tr! similar_chars, letter.to_s
  end
end
normalized() click to toggle source
# File lib/core_extended/string.rb, line 59
def normalized
  self.dup.tap(&:normalized!)
end
normalized!() click to toggle source
# File lib/core_extended/string.rb, line 51
def normalized!
  self.strip!
  self.gsub! /\s/, '_'
  self.unaccented!
  self.letterize!
  self.downcase!
end
unaccented() click to toggle source
# File lib/core_extended/string.rb, line 37
def unaccented
  self.dup.tap(&:unaccented!)
end
unaccented!() click to toggle source
# File lib/core_extended/string.rb, line 29
def unaccented!
  ACCENTS_MAPPING.each do |letter,map|
    tr! map['upcase'], letter
    tr! map['downcase'], letter.downcase
  end
  nil
end
underscore() click to toggle source
# File lib/core_extended/string.rb, line 64
def underscore
  self.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end
upcase() click to toggle source
# File lib/core_extended/string.rb, line 14
def upcase
  self.dup.tap(&:upcase!)
end
upcase!() click to toggle source
# File lib/core_extended/string.rb, line 8
def upcase!
  ACCENTS_MAPPING.values.each { |map| tr! map['downcase'], map['upcase'] }
  tr! CASE_EXTENSION['downcase'], CASE_EXTENSION['upcase']
  upcase_ignoring_accents!
end
Also aliased as: upcase_ignoring_accents!
upcase_ignoring_accents!()
Alias for: upcase!