Class: Copyleaks::CopyleaksTextModerationRequestModel

Inherits:
Object
  • Object
show all
Defined in:
lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: '', sandbox: false, language: nil, labels: []) ⇒ CopyleaksTextModerationRequestModel

Returns a new instance of CopyleaksTextModerationRequestModel.

Parameters:

  • text (String) (defaults to: '')

    Text to produce Text Moderation report for.

  • sandbox (Boolean) (defaults to: false)

    Use sandbox mode to test your integration. Default: false.

  • language (String, nil) (defaults to: nil)

    The language code. Optional; set to nil for auto-detect.

  • labels (Array<Object>) (defaults to: [])

    A list of label configurations (min 1, max 32 elements).

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 34

def initialize(text: '', sandbox: false, language: nil, labels: [])

  @text = text
  @sandbox = sandbox
  @language = language
  @labels = labels

  raise ArgumentError, "String cannot be blank" if @text.nil?
  raise ArgumentError, "Labels must be a non-empty array." unless labels.is_a?(Array) && !labels.empty?
  raise ArgumentError, "Labels cannot have more than 32 elements." if labels.length > 32

end

Instance Attribute Details

#labelsObject

Returns the value of attribute labels.



28
29
30
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 28

def labels
  @labels
end

#languageObject

Returns the value of attribute language.



28
29
30
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 28

def language
  @language
end

#sandboxObject

Returns the value of attribute sandbox.



28
29
30
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 28

def sandbox
  @sandbox
end

#textObject

Returns the value of attribute text.



28
29
30
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 28

def text
  @text
end

Class Method Details

.from_json(json_string) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 56

def self.from_json(json_string)
  data = JSON.parse(json_string, symbolize_names: true)
  new(
    text: data[:text],
    sandbox: data[:sandbox],
    language: data[:language],
    labels: data[:labels]
  )
end

Instance Method Details

#to_json(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/copyleaks/models/textModeration/requests/CopyleaksTextModerationRequestModel.rb', line 47

def to_json(options = {})
  {
    text: @text,
    sandbox: @sandbox,
    language: @language,
    labels: @labels
  }.to_json(options)
end