Class: Tongues::ApiConnexion
- Inherits:
-
Object
- Object
- Tongues::ApiConnexion
- Defined in:
- lib/tongues/api_connexion.rb
Class Method Summary collapse
-
.detect(text) ⇒ Object
Detects the language for the text in params.
Class Method Details
.detect(text) ⇒ Object
Detects the language for the text in params
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tongues/api_connexion.rb', line 13 def detect(text) raise NoApiKeyError, 'Invalid api key. Check config/initializers/tongues.rb' if Tongues::Configuration.api_key.blank? response = call_api(text) if detection = parse_response(response) lang_symbol = detection['language'] language = Tongues::Configuration.languages[lang_symbol] confidence = detection['confidence'] Tongue.new(lang_symbol, language, confidence) end end |