Class: Legion::Extensions::Agentic::Memory::Paleontology::Helpers::Excavation

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_stratum:) ⇒ Excavation

Returns a new instance of Excavation.



13
14
15
16
17
18
19
20
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 13

def initialize(target_stratum:)
  @id             = SecureRandom.uuid
  @target_stratum = target_stratum.to_i.clamp(0, 4)
  @fossils_found  = []
  @started_at     = Time.now.utc
  @completed_at   = nil
  @status         = :in_progress
end

Instance Attribute Details

#completed_atObject (readonly)

Returns the value of attribute completed_at.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def completed_at
  @completed_at
end

#fossils_foundObject (readonly)

Returns the value of attribute fossils_found.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def fossils_found
  @fossils_found
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def id
  @id
end

#started_atObject (readonly)

Returns the value of attribute started_at.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def started_at
  @started_at
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def status
  @status
end

#target_stratumObject (readonly)

Returns the value of attribute target_stratum.



10
11
12
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 10

def target_stratum
  @target_stratum
end

Instance Method Details

#complete!Object



26
27
28
29
30
31
32
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 26

def complete!
  return false if @status == :completed

  @completed_at = Time.now.utc
  @status       = :completed
  true
end

#completed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 34

def completed?
  @status == :completed
end

#record_find!(fossil) ⇒ Object



22
23
24
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 22

def record_find!(fossil)
  @fossils_found << fossil
end

#to_hObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 44

def to_h
  {
    id:             @id,
    target_stratum: @target_stratum,
    stratum_label:  Constants::STRATUM_LABELS[@target_stratum],
    fossils_count:  @fossils_found.size,
    yield_rate:     yield_rate.round(10),
    status:         @status,
    started_at:     @started_at,
    completed_at:   @completed_at
  }
end

#yield_rateObject



38
39
40
41
42
# File 'lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb', line 38

def yield_rate
  return 0.0 if @fossils_found.empty?

  @fossils_found.sum(&:significance) / @fossils_found.size
end