Class: Linguin::ProfanityDetection

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

Overview

Linguin::ProfanityDetection

Returned by Linguin#detect_profanity(!).

#success? - Bool - checks if detection results were found #error - Hash - contains ‘error` and `message` about what went wrong #result - Float - profanity score 0.0..1.0

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

#scoreObject

Returns the value of attribute score.



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

def score
  @score
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/profanity_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/profanity_detection.rb', line 15

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

.success(result) ⇒ Object



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

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

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  !!@success
end