class Translator::Translate

Attributes

from[RW]
string[R]
to[RW]

Public Class Methods

new(string, to: '', from: '') click to toggle source
# File lib/translator.rb, line 13
def initialize(string, to: '', from: '')
  @string = string
  @to = to
  @from = from

  if to.empty? && from.empty?
    @to = Translator::ConfigFile.default_to || 'auto'
    @from = Translator::ConfigFile.default_from
  end
end

Public Instance Methods

parsed_string() click to toggle source
# File lib/translator.rb, line 40
def parsed_string
  string.split(' ').join('%20')
end
result() click to toggle source
# File lib/translator.rb, line 32
def result
  find('#result_box').text
end
translate!() click to toggle source
# File lib/translator.rb, line 24
def translate!
  visit_google_translator

  sleep 3

  result.colorize(:light_green)
end
visit_google_translator() click to toggle source
# File lib/translator.rb, line 36
def visit_google_translator
  visit "https://translate.google.com.br/?source=osdd##{from}/#{to}/#{parsed_string}"
end