Class: Linguin::LanguageDetection

Inherits:
BaseResponse show all
Defined in:
lib/linguin/language_detection.rb

Overview

Linguin::LanguageDetection

Returned by Linguin#detect_language(!).

#success? - Bool - checks if detection results were found #error - Hash - contains ‘error` and `message` about what went wrong #results - Array - contains the detection results, ordered by confidence descending

Direct Known Subclasses

BulkLanguageDetection

Constant Summary

Constants inherited from BaseResponse

BaseResponse::CODE_MAP

Instance Attribute Summary collapse

Attributes inherited from BaseResponse

#error

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResponse

from_httparty, #initialize, #raise_on_error!

Constructor Details

This class inherits a constructor from Linguin::BaseResponse

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



12
13
14
# File 'lib/linguin/language_detection.rb', line 12

def results
  @results
end

#success=(value) ⇒ Object (writeonly)

Sets the attribute success

Parameters:

  • value

    the value to set the attribute success to.



11
12
13
# File 'lib/linguin/language_detection.rb', line 11

def success=(value)
  @success = value
end

Class Method Details

.error(code, message) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/linguin/language_detection.rb', line 15

def error(code, message)
  new do |detection|
    detection.success = false
    detection.error = {
      code: code,
      message: message
    }
  end
end

.success(results) ⇒ Object



25
26
27
28
29
30
# File 'lib/linguin/language_detection.rb', line 25

def success(results)
  new do |detection|
    detection.success = true
    detection.results = results[:results]
  end
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/linguin/language_detection.rb', line 33

def success?
  !!@success
end