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

#[](key) ⇒ Object



18
19
20
# File 'lib/attentive/message.rb', line 18

def [](key)
  tokens[key]
end

#[]=(key, value) ⇒ Object



22
23
24
# File 'lib/attentive/message.rb', line 22

def []=(key, value)
  tokens[key] = value
end

#inspectObject



32
33
34
# File 'lib/attentive/message.rb', line 32

def inspect
  tokens.inspect
end

#lengthObject



26
27
28
# File 'lib/attentive/message.rb', line 26

def length
  tokens.length
end

#tokensObject



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

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