module Normalizacion
Constants
- COLLATION
- VERSION
Public Instance Methods
normalize(downcase: false, strip: true, replace_whitespaces: '-')
click to toggle source
Returns a new String based on pre-defined normalization rules
Available keyword options¶ ↑
-
:downcase
- convert to lower case (true|false, default: false) -
:strip
- trim leading and trailing whitespaces (true|false, default: true) -
:replace_whitespaces
- replace whitespaces within the string withstr
or set tofalse
to leave whitespaces alone. Makes little sense w/o :strip => true (str|false, default: “-”)
Examples¶ ↑
"This is án exåmple".normalize => "This-is-an-example "Tëst string with träiling whitespaces ".normalize(:replace_whitespaces => false) => "Test string with traeiling whitespaces"
# File lib/normalizacion.rb, line 77 def normalize(downcase: false, strip: true, replace_whitespaces: '-') n_str = Normalizacion::COLLATION.inject(dup) {|str, (collate_from, collate_to)| str.gsub(collate_from, collate_to)} n_str.strip! if strip n_str.downcase! if downcase n_str.gsub!(/\s+/, replace_whitespaces) if replace_whitespaces n_str end