Class: Nele::GenericTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/nele/generic_translator.rb

Direct Known Subclasses

BabelfishTranslator, MsTranslator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenericTranslator

Returns a new instance of GenericTranslator.



10
11
12
# File 'lib/nele/generic_translator.rb', line 10

def initialize
  validate_children()
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/nele/generic_translator.rb', line 4

def config
  @config
end

#uriObject (readonly)

Returns the value of attribute uri.



3
4
5
# File 'lib/nele/generic_translator.rb', line 3

def uri
  @uri
end

Class Method Details

.build_translator_class_name(name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/nele/generic_translator.rb', line 30

def build_translator_class_name(name)
  klass_name = name.to_s.capitalize + "Translator"
  begin
    Nele.const_get(klass_name)
  rescue NameError
    raise(::Nele::TranslatorInvalidError, "invalid translator")
  end
end

.check_inheritance(klass) ⇒ Object



39
40
41
42
43
# File 'lib/nele/generic_translator.rb', line 39

def check_inheritance(klass)
  raise(::Nele::TranslatorMissingError,
    "translator should inherit from GenericTranslator"
    ) if klass.superclass != Nele::GenericTranslator
end

Instance Method Details

#nameObject



18
19
20
21
# File 'lib/nele/generic_translator.rb', line 18

def name
  klass_name = self.class.to_s.split("::")[1]
  @name ||= klass_name.split('Translator')[0].downcase
end

#parse_uri(uri) ⇒ Object



14
15
16
# File 'lib/nele/generic_translator.rb', line 14

def parse_uri(uri)
  URI.parse(uri.gsub(" ", "+"))
end

#translate(str) ⇒ Object



23
24
25
26
27
# File 'lib/nele/generic_translator.rb', line 23

def translate(str)
  build_request(str)
  res = connect()
  parse_response(res)
end