class AwsDetectSentiment::Assign
Attributes
api_client[RW]
scope[RW]
text_field[RW]
Public Class Methods
new(scope:, text_field:, api_client: AwsDetectSentiment::AwsComprehendClient.new)
click to toggle source
@param scope [Array<::Object>] @param text_field
[Symbol] @param api_client
[Object]
# File lib/aws_detect_sentiment/assign.rb, line 6 def initialize(scope:, text_field:, api_client: AwsDetectSentiment::AwsComprehendClient.new) self.scope = scope self.text_field = text_field self.api_client = api_client end
Public Instance Methods
perform() { |record, sentiments| ... }
click to toggle source
# File lib/aws_detect_sentiment/assign.rb, line 12 def perform records.each_with_index do |record, index| yield(record, sentiments[index]) end end
Private Instance Methods
records()
click to toggle source
# File lib/aws_detect_sentiment/assign.rb, line 20 def records scope.reject { |record| record.public_send(text_field).to_s.empty? } end
sentiments()
click to toggle source
# File lib/aws_detect_sentiment/assign.rb, line 26 def sentiments @sentiments ||= api_client.detect_sentiments(texts) end
texts()
click to toggle source
# File lib/aws_detect_sentiment/assign.rb, line 30 def texts scope.map { |record| record.public_send(text_field) } end