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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(material:, domain:, content:, color: nil, fit_quality: nil) ⇒ Tessera

Returns a new instance of Tessera.



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

def initialize(material:, domain:, content:,
               color: nil, fit_quality: nil)
  validate_material!(material)
  @id          = SecureRandom.uuid
  @material    = material.to_sym
  @domain      = domain.to_sym
  @content     = content.to_s
  @color       = (color || random_color).to_sym
  @fit_quality = (fit_quality || 0.5).to_f.clamp(0.0, 1.0).round(10)
  @placed_at   = nil
  @mosaic_id   = nil
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



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

def color
  @color
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#fit_qualityObject

Returns the value of attribute fit_quality.



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

def fit_quality
  @fit_quality
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#materialObject (readonly)

Returns the value of attribute material.



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

def material
  @material
end

#mosaic_idObject (readonly)

Returns the value of attribute mosaic_id.



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

def mosaic_id
  @mosaic_id
end

#placed_atObject (readonly)

Returns the value of attribute placed_at.



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

def placed_at
  @placed_at
end

Instance Method Details

#loose?Boolean

Returns:

  • (Boolean)


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

def loose?
  @mosaic_id.nil?
end

#perfect_fit?Boolean

Returns:

  • (Boolean)


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

def perfect_fit?
  @fit_quality >= 0.9
end

#place!(mosaic_id) ⇒ Object



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

def place!(mosaic_id)
  @mosaic_id = mosaic_id
  @placed_at = Time.now.utc
  self
end

#placed?Boolean

Returns:

  • (Boolean)


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

def placed?
  !@mosaic_id.nil?
end

#poor_fit?Boolean

Returns:

  • (Boolean)


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

def poor_fit?
  @fit_quality < 0.3
end

#to_hObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/integration/mosaic/helpers/tessera.rb', line 49

def to_h
  {
    id:          @id,
    material:    @material,
    domain:      @domain,
    content:     @content,
    color:       @color,
    fit_quality: @fit_quality,
    placed:      placed?,
    loose:       loose?,
    perfect_fit: perfect_fit?,
    poor_fit:    poor_fit?,
    mosaic_id:   @mosaic_id,
    placed_at:   @placed_at
  }
end