Module: Preformatter

Included in:
ActiveRecord::Base
Defined in:
lib/preformatter.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.has_spanish_chars?(string) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/preformatter.rb', line 7

def self.has_spanish_chars?(string)
  string.index(/[áéíóúñÑÁÉÍÓÚ]/) rescue nil
end

.included(base) ⇒ Object



3
4
5
# File 'lib/preformatter.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

.replace_spanish_chars_in(string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/preformatter.rb', line 11

def self.replace_spanish_chars_in(string)
  replace = {'á' => 'a','é' => 'e','í' => 'i','ó' => 'o','ú' => 'u', 
             'ñ' => 'n', 'Ñ' => 'N', 
             'Á' => 'A' , 'É' => 'E',  'Í' => 'I', 'Ó' => 'O','Ú' => 'U'}
  unless string.nil?
    string_with_no_spanish_chars = string.gsub(/[#{replace.keys.join('|')}]/).each do |c|
      replace[c]
    end
    return string_with_no_spanish_chars
  end
end