Class: Oversetter::Hablaa::Translate

Inherits:
Object
  • Object
show all
Defined in:
lib/oversetter/hablaa/translate.rb

Overview

Fetches translations from Hablaa.

Instance Method Summary collapse

Instance Method Details

#get_trans(search, params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oversetter/hablaa/translate.rb', line 10

def get_trans(search, params)
  func, result = 'translation', nil
  tran = Oversetter::Hablaa.new
  result = tran.get_word(search, func, params, result)
  if result != 'error'
    result = MultiJson.load(result)
    result = result[0]
    st = { 'searchterm' => URI.decode(search) }
    type = { 'type' => 'translation' }
    Oversetter.tofile(st)
    Oversetter.tofile(type)
    label = 'Translation'
    Oversetter.label(label)
    text = result['text']
    source = result['source']
    pos = result['pos']
    print Rainbow('Text|').bright
    print "#{text}|"
    print Rainbow('Source|').bright
    print "#{source}|"
    t = { 'text' => text }
    s = { 'source' => source }
    Oversetter.tofile(t)
    Oversetter.tofile(s)
    if pos['code'] != nil
      print Rainbow('POS code|').bright
      print "#{pos['code']}|"
      pc = { 'pos code' => pos['code'] }
      Oversetter.tofile(pc)
    end
    if pos['title'] != nil
      print Rainbow('Part of speech|').bright
      print "#{pos['title']}|"
      pt = { 'pos title' => pos['title']}
      Oversetter.tofile(pt)
    end
    puts ''
  else
    puts 'Hablaa found no results.'
  end
end