Class: Legion::Extensions::Agentic::Self::SelfTalk::Helpers::InnerVoice

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, voice_type:, volume: Constants::DEFAULT_VOLUME, bias_direction: nil, active: true) ⇒ InnerVoice

Returns a new instance of InnerVoice.



15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 15

def initialize(name:, voice_type:, volume: Constants::DEFAULT_VOLUME, bias_direction: nil, active: true)
  @id             = SecureRandom.uuid
  @name           = name
  @voice_type     = voice_type
  @volume         = volume.clamp(0.0, 1.0)
  @bias_direction = bias_direction
  @active         = active
  @created_at     = Time.now.utc
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



13
14
15
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 13

def active
  @active
end

#bias_directionObject (readonly)

Returns the value of attribute bias_direction.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 12

def bias_direction
  @bias_direction
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 12

def name
  @name
end

#voice_typeObject (readonly)

Returns the value of attribute voice_type.



12
13
14
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 12

def voice_type
  @voice_type
end

#volumeObject

Returns the value of attribute volume.



13
14
15
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 13

def volume
  @volume
end

Instance Method Details

#amplify!(amount = Constants::VOLUME_BOOST) ⇒ Object



25
26
27
28
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 25

def amplify!(amount = Constants::VOLUME_BOOST)
  @volume = (@volume + amount).clamp(0.0, 1.0)
  self
end

#dampen!(amount = Constants::VOLUME_DECAY) ⇒ Object



30
31
32
33
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 30

def dampen!(amount = Constants::VOLUME_DECAY)
  @volume = (@volume - amount).clamp(0.0, 1.0)
  self
end

#dominant?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 45

def dominant?
  @volume >= 0.7
end

#mute!Object



35
36
37
38
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 35

def mute!
  @active = false
  self
end

#quiet?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 49

def quiet?
  @volume <= 0.3
end

#to_hObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 57

def to_h
  {
    id:             @id,
    name:           @name,
    voice_type:     @voice_type,
    volume:         @volume.round(10),
    volume_label:   volume_label,
    bias_direction: @bias_direction,
    active:         @active,
    dominant:       dominant?,
    quiet:          quiet?,
    created_at:     @created_at
  }
end

#unmute!Object



40
41
42
43
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 40

def unmute!
  @active = true
  self
end

#volume_labelObject



53
54
55
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb', line 53

def volume_label
  Constants.dominance_label(@volume)
end