Class: Cirrocumulus::Message

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

Overview

Message. Used by agents to communicate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sender, act, content) ⇒ Message

Returns a new instance of Message.



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

def initialize(sender, act, content)
  @sender = sender
  @act = act
  @content = content
end

Instance Attribute Details

#actObject

Returns the value of attribute act.



4
5
6
# File 'lib/cirrocumulus/agents/message.rb', line 4

def act
  @act
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/cirrocumulus/agents/message.rb', line 4

def content
  @content
end

#conversation_idObject

Returns the value of attribute conversation_id.



5
6
7
# File 'lib/cirrocumulus/agents/message.rb', line 5

def conversation_id
  @conversation_id
end

#in_reply_toObject

Returns the value of attribute in_reply_to.



5
6
7
# File 'lib/cirrocumulus/agents/message.rb', line 5

def in_reply_to
  @in_reply_to
end

#ontologyObject

Returns the value of attribute ontology.



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

def ontology
  @ontology
end

#receiverObject

Returns the value of attribute receiver.



5
6
7
# File 'lib/cirrocumulus/agents/message.rb', line 5

def receiver
  @receiver
end

#reply_withObject

Returns the value of attribute reply_with.



5
6
7
# File 'lib/cirrocumulus/agents/message.rb', line 5

def reply_with
  @reply_with
end

#senderObject

Returns the value of attribute sender.



4
5
6
# File 'lib/cirrocumulus/agents/message.rb', line 4

def sender
  @sender
end

Class Method Details

.parse_params(content, subroutine = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cirrocumulus/agents/message.rb', line 22

def self.parse_params(content, subroutine = false)
  return parse_params(content.size == 1 ? content[0] : content, true)  if !subroutine

  return [] if content.nil?
  return content if !content.is_a?(Array)
  return [] if content.size == 0
  return {content[0] => []} if content.size == 1
  return {content[0] => parse_params(content[1], true)} if content.size == 2

  res = {content[0] => []}

  if content.all? {|item| !item.is_a?(Array)}
    content.each_with_index do |item,i|
      if i == 0
        res[content[0]] = []
      else
        res[content[0]] << item
      end
    end
  else
    content.each_with_index do |item,i|
      if i == 0
        res[content[0]] = {}
      else
        res[content[0]].merge!(parse_params(item, true))
      end
    end
  end

  res
end

Instance Method Details

#contextObject



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

def context
  Context.new(self.sender, self.reply_with, self.conversation_id)
end

#failed?Boolean

Returns:

  • (Boolean)


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

def failed?
  act == 'failure' || act == 'refuse'
end