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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, episode_type:, emotional_valence:, significance:, domain:) ⇒ Episode

Returns a new instance of Episode.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb', line 16

def initialize(content:, episode_type:, emotional_valence:, significance:, domain:, **)
  @id                = SecureRandom.uuid
  @content           = content
  @episode_type      = episode_type
  @emotional_valence = emotional_valence.clamp(-1.0, 1.0)
  @significance      = significance.clamp(0.0, 1.0)
  @domain            = domain
  @chapter_id        = nil
  @themes            = []
  @created_at        = Time.now.utc
end

Instance Attribute Details

#chapter_idObject

Returns the value of attribute chapter_id.



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

def chapter_id
  @chapter_id
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#emotional_valenceObject (readonly)

Returns the value of attribute emotional_valence.



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

def emotional_valence
  @emotional_valence
end

#episode_typeObject (readonly)

Returns the value of attribute episode_type.



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

def episode_type
  @episode_type
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#significanceObject (readonly)

Returns the value of attribute significance.



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

def significance
  @significance
end

#themesObject (readonly)

Returns the value of attribute themes.



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

def themes
  @themes
end

Instance Method Details

#defining?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb', line 36

def defining?
  @significance >= 0.8
end

#negative?Boolean

Returns:

  • (Boolean)


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

def negative?
  @emotional_valence.negative?
end

#positive?Boolean

Returns:

  • (Boolean)


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

def positive?
  @emotional_valence.positive?
end

#significance_labelObject



40
41
42
43
44
45
46
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb', line 40

def significance_label
  Constants::SIGNIFICANCE_LABELS.each do |entry|
    range, label = entry.first
    return label if range.cover?(@significance)
  end
  :trivial
end

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb', line 48

def to_h
  {
    id:                @id,
    content:           @content,
    episode_type:      @episode_type,
    emotional_valence: @emotional_valence,
    significance:      @significance,
    domain:            @domain,
    chapter_id:        @chapter_id,
    themes:            @themes.dup,
    created_at:        @created_at
  }
end