Class: Copyleaks::CopyleaksTextModerationResponseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(moderations: ModerationsModel.new, legend: [], scanned_document: TextModerationScannedDocument.new, **_ignored) ⇒ CopyleaksTextModerationResponseModel

Returns a new instance of CopyleaksTextModerationResponseModel.

Parameters:

  • moderations (ModerationsModel) (defaults to: ModerationsModel.new)

    Moderated text segments detected in the input text.

  • legend (Array<TextModerationsLegend>) (defaults to: [])

    An array that provides a lookup for the labels referenced by their numerical indices in the ‘text.chars.labels` array. Each object within this legend array defines a specific label that was used in the scan.

  • scanned_document (TextModerationScannedDocument) (defaults to: TextModerationScannedDocument.new)

    General information about the scanned document.



10
11
12
13
14
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 10

def initialize(moderations: ModerationsModel.new, legend: [], scanned_document: TextModerationScannedDocument.new, **_ignored)
  @moderations = moderations
  @legend = legend
  @scanned_document = scanned_document
end

Instance Attribute Details

#legendObject

Returns the value of attribute legend.



5
6
7
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 5

def legend
  @legend
end

#moderationsObject

Returns the value of attribute moderations.



5
6
7
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 5

def moderations
  @moderations
end

#scanned_documentObject

Returns the value of attribute scanned_document.



5
6
7
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 5

def scanned_document
  @scanned_document
end

Class Method Details

.from_json(json_string) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 26

def self.from_json(json_string)
  data = JSON.parse(json_string, symbolize_names: true)
  new(
    moderations: data[:moderations] ? ModerationsModel.from_json(data[:moderations].to_json) : nil,
    legend: data[:legend].map { |l| TextModerationsLegend.from_json(l.to_json) },
    scanned_document: data[:scannedDocument] ? TextModerationScannedDocument.from_json(data[:scannedDocument].to_json) : nil
  )
end

Instance Method Details

#to_json(options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/copyleaks/models/textModeration/responses/CopyleaksTextModerationResponseModel.rb', line 17

def to_json(options = {})
  {
    moderations: @moderations ? JSON.parse(@moderations.to_json) : nil,
    legend: @legend.map(&:to_json).map { |l| JSON.parse(l) },
    scannedDocument: @scanned_document ? JSON.parse(@scanned_document.to_json) : nil
  }.to_json(options)
end