Class: Legion::Extensions::Agentic::Language::Narrator::Helpers::Journal

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/language/narrator/helpers/journal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJournal

Returns a new instance of Journal.



12
13
14
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 12

def initialize
  @entries = []
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



10
11
12
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 10

def entries
  @entries
end

Instance Method Details

#append(entry) ⇒ Object



16
17
18
19
20
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 16

def append(entry)
  @entries << entry
  trim_to_capacity
  entry
end

#by_mood(mood) ⇒ Object



30
31
32
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 30

def by_mood(mood)
  @entries.select { |e| e[:mood] == mood }
end

#clearObject



38
39
40
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 38

def clear
  @entries.clear
end

#recent(limit: 10) ⇒ Object



22
23
24
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 22

def recent(limit: 10)
  @entries.last(limit)
end

#since(timestamp) ⇒ Object



26
27
28
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 26

def since(timestamp)
  @entries.select { |e| e[:timestamp] >= timestamp }
end

#sizeObject



34
35
36
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 34

def size
  @entries.size
end

#statsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 42

def stats
  return { total: 0, moods: {} } if @entries.empty?

  mood_counts = @entries.each_with_object(Hash.new(0)) { |e, h| h[e[:mood]] += 1 }
  {
    total:    @entries.size,
    moods:    mood_counts,
    oldest:   @entries.first[:timestamp],
    newest:   @entries.last[:timestamp],
    capacity: Constants::MAX_JOURNAL_SIZE
  }
end