class Transleet

Constants

GOOGLE_TRANSLATE_TEMPLATE
VERSION

Public Class Methods

new(from_language, to_language) click to toggle source
# File lib/transleet.rb, line 10
def initialize(from_language, to_language)
  @from_language = from_language
  @to_language = to_language
end

Public Instance Methods

build_request(from, to, sentence) click to toggle source
# File lib/transleet.rb, line 21
def build_request(from, to, sentence)
  GOOGLE_TRANSLATE_TEMPLATE.gsub("[[sentence]]", sentence.to_uri)
    .gsub("[[to]]", to)
    .gsub("[[from]]", from)
end
parse_translation(response) click to toggle source
# File lib/transleet.rb, line 27
def parse_translation(response)
  response.split('"')[1]
end
translate(sentence) click to toggle source
# File lib/transleet.rb, line 15
def translate(sentence)
  request_string = build_request(@from_language, @to_language, sentence)
  raw_response = HTTParty.get(request_string)
  parse_translation(raw_response)
end