Class: Legion::Extensions::Agentic::Integration::Mosaic::Helpers::Mosaic

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, pattern_category:, capacity: 50, grout_strength: nil) ⇒ Mosaic

Returns a new instance of Mosaic.



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 14

def initialize(name:, pattern_category:, capacity: 50, grout_strength: nil)
  validate_pattern!(pattern_category)
  @id               = SecureRandom.uuid
  @name             = name.to_s
  @pattern_category = pattern_category.to_sym
  @tessera_ids      = []
  @capacity         = capacity.to_i.clamp(1, 500)
  @grout_strength   = (grout_strength || 0.8).to_f.clamp(0.0, 1.0).round(10)
  @created_at       = Time.now.utc
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def capacity
  @capacity
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def created_at
  @created_at
end

#grout_strengthObject

Returns the value of attribute grout_strength.



12
13
14
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 12

def grout_strength
  @grout_strength
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def name
  @name
end

#pattern_categoryObject (readonly)

Returns the value of attribute pattern_category.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def pattern_category
  @pattern_category
end

#tessera_idsObject (readonly)

Returns the value of attribute tessera_ids.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 10

def tessera_ids
  @tessera_ids
end

Instance Method Details

#add_tessera(tessera_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 25

def add_tessera(tessera_id)
  return false if @tessera_ids.include?(tessera_id)
  return false if full?

  @tessera_ids << tessera_id
  true
end

#completenessObject



49
50
51
52
53
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 49

def completeness
  return 0.0 if @capacity.zero?

  (@tessera_ids.size.to_f / @capacity).clamp(0.0, 1.0).round(10)
end

#completeness_labelObject



69
70
71
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 69

def completeness_label
  Constants.label_for(Constants::COMPLETENESS_LABELS, completeness)
end

#crumbling?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 65

def crumbling?
  @grout_strength < 0.2
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 45

def empty?
  @tessera_ids.empty?
end

#erode_grout!(rate: Constants::GROUT_DECAY) ⇒ Object



55
56
57
58
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 55

def erode_grout!(rate: Constants::GROUT_DECAY)
  @grout_strength = (@grout_strength - rate.abs).clamp(0.0, 1.0).round(10)
  self
end

#full?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 41

def full?
  @tessera_ids.size >= @capacity
end

#gap_countObject



73
74
75
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 73

def gap_count
  @capacity - @tessera_ids.size
end

#reinforce_grout!(boost: 0.1) ⇒ Object



60
61
62
63
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 60

def reinforce_grout!(boost: 0.1)
  @grout_strength = (@grout_strength + boost.abs).clamp(0.0, 1.0).round(10)
  self
end

#remove_tessera(tessera_id) ⇒ Object



33
34
35
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 33

def remove_tessera(tessera_id)
  @tessera_ids.delete(tessera_id) ? true : false
end

#sizeObject



37
38
39
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 37

def size
  @tessera_ids.size
end

#to_hObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb', line 77

def to_h
  {
    id:                 @id,
    name:               @name,
    pattern_category:   @pattern_category,
    tessera_ids:        @tessera_ids.dup,
    size:               size,
    capacity:           @capacity,
    completeness:       completeness,
    completeness_label: completeness_label,
    grout_strength:     @grout_strength,
    gap_count:          gap_count,
    full:               full?,
    empty:              empty?,
    crumbling:          crumbling?,
    created_at:         @created_at
  }
end