Module: XxxRename::CoreExtensions::String

Defined in:
lib/xxx_rename/core_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#normalizeString

Remove the following characters from the input string and returns it in lower case

s : whitespace characters W : any non-word character _ : underscore

Returns:



14
15
16
# File 'lib/xxx_rename/core_extensions/string.rb', line 14

def normalize
  gsub(/[\s\W_]/, "").downcase
end

#remove_special_charactersObject

Remove any characters not included in the following list w [a-zA-Z0-9_]. s Whitespace character

  • hyphen

, comma [ brackets ] brackets



34
35
36
# File 'lib/xxx_rename/core_extensions/string.rb', line 34

def remove_special_characters
  gsub(/[^\w\s\-,\[\]']/, "").gsub(/\s{2,}/, " ")
end

#titleize_customString

Returns:



19
20
21
22
23
24
25
# File 'lib/xxx_rename/core_extensions/string.rb', line 19

def titleize_custom
  re = /([A-Z]\d[A-Z]|[A-Z][a-zA-Z])/
  res = []
  scan(re) { |_| res << Regexp.last_match.offset(0)[0] }
  res.reverse.each { |index| insert(index, " ") }
  strip
end