Class: Attentive::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/attentive/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, params = {}) ⇒ Message

Returns a new instance of Message.



8
9
10
11
12
# File 'lib/attentive/message.rb', line 8

def initialize(text, params={})
  @text = text
  @contexts = Set.new(params.fetch(:contexts, []))
  contexts << :conversation if tokens.grep(Attentive::Tokens::Invocation).any?
end

Instance Attribute Details

#contextsObject (readonly)

Returns the value of attribute contexts.



6
7
8
# File 'lib/attentive/message.rb', line 6

def contexts
  @contexts
end

#textObject (readonly) Also known as: to_s

Returns the value of attribute text.



6
7
8
# File 'lib/attentive/message.rb', line 6

def text
  @text
end

Instance Method Details

#inspectObject



20
21
22
# File 'lib/attentive/message.rb', line 20

def inspect
  tokens.inspect
end

#tokensObject



14
15
16
# File 'lib/attentive/message.rb', line 14

def tokens
  @tokens ||= Attentive::Tokenizer.tokenize(text)
end