class Dater::Translator
Constants
- PORTUGUESE
- SPANISH
- SUPPORTED_LANGUAGES
Public Class Methods
new(lang)
click to toggle source
# File lib/translator.rb, line 59 def initialize(lang) raise "Languaje #{lang} not supported" unless SUPPORTED_LANGUAGES.include? lang @lang = lang @dictionary = @lang == "es" ? SPANISH : PORTUGUESE end
Public Instance Methods
get_english_for(word)
click to toggle source
# File lib/translator.rb, line 76 def get_english_for word @dictionary.each_pair do |k,v| return k.to_s if word =~ v end word end
mapper(word)
click to toggle source
# File lib/translator.rb, line 70 def mapper word word.split(" ").map do |word| get_english_for word end.join(" ") end
no_special_chars(arg)
click to toggle source
# File lib/translator.rb, line 83 def no_special_chars(arg) arg.gsub(/(á|Á)/, 'a').gsub(/(é|É)/, 'e').gsub(/(í|Í)/, 'i').gsub(/(ó|Ó)/, 'o').gsub(/(ú|Ú)/, 'u').gsub(/(ç|Ç)/, 'c').downcase end
this(word)
click to toggle source
# File lib/translator.rb, line 65 def this word return word if @lang=="en" mapper no_special_chars(word) end