Class: ClaudeMemory::Dashboard::FactPresenter
- Inherits:
-
Object
- Object
- ClaudeMemory::Dashboard::FactPresenter
- Defined in:
- lib/claude_memory/dashboard/fact_presenter.rb
Overview
Shapes a facts-table row into the hashes the dashboard API emits. Callers opt in to the shape they need:
-
#summary — full fact with confidence, scope, created_at, created_ago
-
#preview — predicate + truncated object for list rows
-
#with_provenance — summary + provenance chain (quote, session_id, occurred_at)
-
#list_summary — batches entity lookups across many rows to avoid N+1
All methods resolve the subject/object entities from the store passed at construction time; callers pass in raw facts-table rows (hashes) directly.
Constant Summary collapse
- OBJECT_PREVIEW_CHARS =
120
Instance Method Summary collapse
-
#initialize(store) ⇒ FactPresenter
constructor
A new instance of FactPresenter.
-
#list_summary(rows) ⇒ Array<Hash>
Summaries with batched entity resolution.
-
#preview(row) ⇒ Hash?
Object text truncated to OBJECT_PREVIEW_CHARS.
-
#summary(row) ⇒ Hash?
Nil when row is nil.
-
#with_provenance(row) ⇒ Hash?
Summary plus :provenance array with session/date context.
Constructor Details
#initialize(store) ⇒ FactPresenter
Returns a new instance of FactPresenter.
18 19 20 |
# File 'lib/claude_memory/dashboard/fact_presenter.rb', line 18 def initialize(store) @store = store end |
Instance Method Details
#list_summary(rows) ⇒ Array<Hash>
Returns summaries with batched entity resolution.
59 60 61 62 63 |
# File 'lib/claude_memory/dashboard/fact_presenter.rb', line 59 def list_summary(rows) ids = rows.flat_map { |r| [r[:subject_entity_id], r[:object_entity_id]] }.compact.uniq entities = ids.empty? ? {} : @store.entities.where(id: ids).as_hash(:id) rows.map { |r| serialize(r, entities) } end |
#preview(row) ⇒ Hash?
Returns object text truncated to OBJECT_PREVIEW_CHARS.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/claude_memory/dashboard/fact_presenter.rb', line 31 def preview(row) return nil unless row entities = load_entities([row[:subject_entity_id], row[:object_entity_id]]) subject = entities[row[:subject_entity_id]] object_entity = entities[row[:object_entity_id]] object_text = row[:object_literal] || object_entity&.dig(:canonical_name) || "unknown" truncated = object_text.to_s.length > OBJECT_PREVIEW_CHARS { id: row[:id], docid: row[:docid], subject: subject&.dig(:canonical_name) || "unknown", predicate: row[:predicate], object: truncated ? "#{object_text[0, OBJECT_PREVIEW_CHARS]}…" : object_text, scope: row[:scope], status: row[:status] } end |
#summary(row) ⇒ Hash?
Returns nil when row is nil.
24 25 26 27 |
# File 'lib/claude_memory/dashboard/fact_presenter.rb', line 24 def summary(row) return nil unless row serialize(row, load_entities([row[:subject_entity_id], row[:object_entity_id]])) end |
#with_provenance(row) ⇒ Hash?
Returns summary plus :provenance array with session/date context.
52 53 54 55 |
# File 'lib/claude_memory/dashboard/fact_presenter.rb', line 52 def with_provenance(row) return nil unless row summary(row).merge(provenance: load_provenance(row[:id])) end |