Class: Oversetter::Glosbe

Inherits:
Object
  • Object
show all
Defined in:
lib/oversetter/glosbe/text.rb,
lib/oversetter/glosbe/example.rb,
lib/oversetter/glosbe/translate.rb

Overview

Glosbeā€™s service provides translations and examples.

Defined Under Namespace

Classes: Example, Translate

Instance Method Summary collapse

Instance Method Details

#get_word(search, func, params, result) ⇒ Object

Parameters:

  • func (String)

    The search function to use.

  • params (Hash)

    The search parameters to use.

  • result (String)

    The search response.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oversetter/glosbe/text.rb', line 11

def get_word(search, func, params, result)
			search = URI.encode(search)
			prefix = 'https://glosbe.com/gapi/'
			word, pcont = "#{prefix}#{func}?", []
			if func == 'translate' then pcont.push "tm=false&"; end
  params.map { |k, v|
    if k == :src then pcont.push "from=#{v}&"; end
if k == :tar then pcont.push "dest=#{v}&"; end
if k == :page then pcont.push "page=#{v}&"; end
if k == :size then pcont.push "pageSize=#{v}&"; end
  }
			pcont.push "phrase=#{search}&format=json&"
  url = "#{word}#{pcont.join}"
  request = HTTPI::Request.new(url)
  getter = HTTPI.get(request)
  result = getter.body
end