Class: AgentsControl::Reply

Inherits:
Object
  • Object
show all
Defined in:
lib/agents_control/reply.rb

Overview

A human's answer to an event.

Also agent-neutral: turning it into the right JSON shape is the adapter's job. Telegram only ever knows these four kinds.

Constant Summary collapse

KINDS =
%i[allow deny text none].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, text: nil, remember: false) ⇒ Reply

Returns a new instance of Reply.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/agents_control/reply.rb', line 22

def initialize(kind:, text: nil, remember: false)
  raise ArgumentError, "unknown reply kind: #{kind}" unless KINDS.include?(kind)

  @kind = kind
  @text = text
  @remember = remember
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



11
12
13
# File 'lib/agents_control/reply.rb', line 11

def kind
  @kind
end

#rememberObject (readonly)

Returns the value of attribute remember.



11
12
13
# File 'lib/agents_control/reply.rb', line 11

def remember
  @remember
end

#textObject (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/agents_control/reply.rb', line 11

def text
  @text
end

Class Method Details

.allow(remember: false) ⇒ Object



13
# File 'lib/agents_control/reply.rb', line 13

def self.allow(remember: false) = new(kind: :allow, remember: remember)

.deny(text = nil) ⇒ Object



14
# File 'lib/agents_control/reply.rb', line 14

def self.deny(text = nil) = new(kind: :deny, text: text)

.noneObject

Nobody answered. A distinct kind rather than nil: silence is itself a decision, and it's treated as a refusal — but it's still worth distinguishing from an explicit "no" in the message shown to the user.



20
# File 'lib/agents_control/reply.rb', line 20

def self.none = new(kind: :none)

.text(value) ⇒ Object



15
# File 'lib/agents_control/reply.rb', line 15

def self.text(value) = new(kind: :text, text: value)

Instance Method Details

#allow?Boolean

Returns:

  • (Boolean)


30
# File 'lib/agents_control/reply.rb', line 30

def allow? = kind == :allow

#deny?Boolean

Returns:

  • (Boolean)


31
# File 'lib/agents_control/reply.rb', line 31

def deny? = kind == :deny

#none?Boolean

Returns:

  • (Boolean)


33
# File 'lib/agents_control/reply.rb', line 33

def none? = kind == :none

#permits?Boolean

Whether to allow the tool. Silence is not permission: if nobody answered while the owner was out, the action doesn't happen.

Returns:

  • (Boolean)


37
# File 'lib/agents_control/reply.rb', line 37

def permits? = allow?

#text?Boolean

Returns:

  • (Boolean)


32
# File 'lib/agents_control/reply.rb', line 32

def text? = kind == :text

#to_hObject



39
# File 'lib/agents_control/reply.rb', line 39

def to_h = { kind: kind, text: text, remember: remember }