Class: ClaudeMemory::Core::TextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/core/text_builder.rb

Overview

Pure logic for building searchable text from structured data Follows Functional Core pattern - no I/O, just transformations

Class Method Summary collapse

Class Method Details

.build_searchable_text(entities, facts, decisions) ⇒ String

Build searchable text from entities, facts, and decisions

Parameters:

  • entities (Array<Hash>)

    Entities with :type and :name

  • facts (Array<Hash>)

    Facts with :subject, :predicate, :object, :quote

  • decisions (Array<Hash>)

    Decisions with :title and :summary

Returns:

  • (String)

    Concatenated searchable text



13
14
15
16
17
18
19
# File 'lib/claude_memory/core/text_builder.rb', line 13

def self.build_searchable_text(entities, facts, decisions)
  parts = []
  entities.each { |e| parts << "#{e[:type]}: #{e[:name]}" }
  facts.each { |f| parts << "#{f[:subject]} #{f[:predicate]} #{f[:object]} #{f[:quote]}" }
  decisions.each { |d| parts << "#{d[:title]} #{d[:summary]}" }
  parts.join(" ").strip
end

.symbolize_keys(hash) ⇒ Hash

Transform hash keys from strings to symbols

Parameters:

  • hash (Hash)

    Hash with string or symbol keys

Returns:

  • (Hash)

    Hash with symbolized keys



35
36
37
# File 'lib/claude_memory/core/text_builder.rb', line 35

def self.symbolize_keys(hash)
  hash.transform_keys(&:to_sym)
end

.truncate(text, max_length, suffix: "...") ⇒ String

Truncate text to a maximum length with a suffix

Parameters:

  • text (String, nil)

    Text to truncate

  • max_length (Integer)

    Maximum length before truncation

  • suffix (String) (defaults to: "...")

    Suffix to append when truncated

Returns:

  • (String)

    Truncated text or original if within limit



26
27
28
29
30
# File 'lib/claude_memory/core/text_builder.rb', line 26

def self.truncate(text, max_length, suffix: "...")
  return "" if text.nil?
  return text if text.length <= max_length
  text[0, max_length] + suffix
end