Class: ClaudeMemory::Domain::Fact

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/domain/fact.rb

Overview

Domain model representing a fact in the memory system. Encapsulates business logic and validation. Instances are immutable (frozen).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Fact

Returns a new instance of Fact.

Parameters:

  • attributes (Hash)

    fact attributes

Options Hash (attributes):

  • :id (Integer)

    database primary key

  • :docid (Integer)

    FTS document id

  • :subject_name (String)

    entity name of the subject

  • :predicate (String)

    relationship type (required)

  • :object_literal (String)

    literal value (required)

  • :status (String)

    one of “active”, “superseded”, “rejected”, “disputed”

  • :confidence (Float)

    score between 0 and 1 (default: 1.0)

  • :scope (String)

    “project” or “global” (default: “project”)

  • :project_path (String)

    path for project-scoped facts

  • :valid_from (String)

    ISO 8601 start of validity

  • :valid_to (String)

    ISO 8601 end of validity (nil if current)

  • :created_at (String)

    ISO 8601 creation timestamp

Raises:

  • (ArgumentError)

    if predicate, object_literal, or confidence is invalid



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/claude_memory/domain/fact.rb', line 26

def initialize(attributes)
  @id = attributes[:id]
  @docid = attributes[:docid]
  @subject_name = attributes[:subject_name]
  @predicate = attributes[:predicate]
  @object_literal = attributes[:object_literal]
  @status = attributes[:status] || "active"
  @confidence = attributes[:confidence] || 1.0
  @scope = attributes[:scope] || "project"
  @project_path = attributes[:project_path]
  @valid_from = attributes[:valid_from]
  @valid_to = attributes[:valid_to]
  @created_at = attributes[:created_at]

  validate!
  freeze
end

Instance Attribute Details

#confidenceObject (readonly)

Returns the value of attribute confidence.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def confidence
  @confidence
end

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def created_at
  @created_at
end

#docidObject (readonly)

Returns the value of attribute docid.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def docid
  @docid
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def id
  @id
end

#object_literalObject (readonly)

Returns the value of attribute object_literal.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def object_literal
  @object_literal
end

#predicateObject (readonly)

Returns the value of attribute predicate.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def predicate
  @predicate
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def project_path
  @project_path
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def scope
  @scope
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def status
  @status
end

#subject_nameObject (readonly)

Returns the value of attribute subject_name.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def subject_name
  @subject_name
end

#valid_fromObject (readonly)

Returns the value of attribute valid_from.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def valid_from
  @valid_from
end

#valid_toObject (readonly)

Returns the value of attribute valid_to.



8
9
10
# File 'lib/claude_memory/domain/fact.rb', line 8

def valid_to
  @valid_to
end

Instance Method Details

#active?Boolean

Returns true when status is “active”.

Returns:

  • (Boolean)

    true when status is “active”



45
46
47
# File 'lib/claude_memory/domain/fact.rb', line 45

def active?
  status == "active"
end

#global?Boolean

Returns true when scope is “global”.

Returns:

  • (Boolean)

    true when scope is “global”



60
61
62
# File 'lib/claude_memory/domain/fact.rb', line 60

def global?
  scope == "global"
end

#project?Boolean

Returns true when scope is “project”.

Returns:

  • (Boolean)

    true when scope is “project”



65
66
67
# File 'lib/claude_memory/domain/fact.rb', line 65

def project?
  scope == "project"
end

#rejected?Boolean

Returns true when status is “rejected”.

Returns:

  • (Boolean)

    true when status is “rejected”



55
56
57
# File 'lib/claude_memory/domain/fact.rb', line 55

def rejected?
  status == "rejected"
end

#superseded?Boolean

Returns true when status is “superseded”.

Returns:

  • (Boolean)

    true when status is “superseded”



50
51
52
# File 'lib/claude_memory/domain/fact.rb', line 50

def superseded?
  status == "superseded"
end

#to_hHash

Returns all attributes as a plain hash.

Returns:

  • (Hash)

    all attributes as a plain hash



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/claude_memory/domain/fact.rb', line 70

def to_h
  {
    id: id,
    docid: docid,
    subject_name: subject_name,
    predicate: predicate,
    object_literal: object_literal,
    status: status,
    confidence: confidence,
    scope: scope,
    project_path: project_path,
    valid_from: valid_from,
    valid_to: valid_to,
    created_at: created_at
  }
end