Class: Legion::Extensions::Agentic::Language::Narrator::Helpers::Journal
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::Narrator::Helpers::Journal
- Defined in:
- lib/legion/extensions/agentic/language/narrator/helpers/journal.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #append(entry) ⇒ Object
- #by_mood(mood) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Journal
constructor
A new instance of Journal.
- #recent(limit: 10) ⇒ Object
- #since(timestamp) ⇒ Object
- #size ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize ⇒ Journal
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
#entries ⇒ Object (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 |
#clear ⇒ Object
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() @entries.select { |e| e[:timestamp] >= } end |
#size ⇒ Object
34 35 36 |
# File 'lib/legion/extensions/agentic/language/narrator/helpers/journal.rb', line 34 def size @entries.size end |
#stats ⇒ Object
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 |