Class: Legion::Extensions::Agentic::Self::NarrativeIdentity::Helpers::Theme

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, theme_type:, strength: 0.0, episode_ids: nil, id: nil) ⇒ Theme

Returns a new instance of Theme.



15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb', line 15

def initialize(name:, theme_type:, strength: 0.0, episode_ids: nil, id: nil)
  @id          = id || SecureRandom.uuid
  @name        = name
  @theme_type  = theme_type
  @strength    = strength.clamp(0.0, 1.0)
  @episode_ids = episode_ids || []
end

Instance Attribute Details

#episode_idsObject (readonly)

Returns the value of attribute episode_ids.



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

def episode_ids
  @episode_ids
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#strengthObject

Returns the value of attribute strength.



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

def strength
  @strength
end

#theme_typeObject (readonly)

Returns the value of attribute theme_type.



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

def theme_type
  @theme_type
end

Instance Method Details

#decay!Object



27
28
29
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb', line 27

def decay!
  @strength = (@strength - Constants::COHERENCE_DECAY).clamp(0.0, 1.0).round(10)
end

#prominent?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb', line 31

def prominent?
  @strength >= 0.6
end

#reinforce!(amount) ⇒ Object



23
24
25
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb', line 23

def reinforce!(amount)
  @strength = (@strength + amount).clamp(0.0, 1.0).round(10)
end

#to_hObject



35
36
37
38
39
40
41
42
43
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb', line 35

def to_h
  {
    id:          @id,
    name:        @name,
    theme_type:  @theme_type,
    strength:    @strength,
    episode_ids: @episode_ids.dup
  }
end