Class: RobotLab::Durable::Entry

Inherits:
Data
  • Object
show all
Defined in:
lib/robot_lab/durable/entry.rb

Constant Summary collapse

CONFIDENCE_INCREMENT =
0.1
MAX_CONFIDENCE =
1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category

Returns:

  • (Object)

    the current value of category



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def category
  @category
end

#confidenceObject (readonly)

Returns the value of attribute confidence

Returns:

  • (Object)

    the current value of confidence



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain

Returns:

  • (Object)

    the current value of domain



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def domain
  @domain
end

#reasoningObject (readonly)

Returns the value of attribute reasoning

Returns:

  • (Object)

    the current value of reasoning



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def reasoning
  @reasoning
end

#updated_atObject (readonly)

Returns the value of attribute updated_at

Returns:

  • (Object)

    the current value of updated_at



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def updated_at
  @updated_at
end

#use_countObject (readonly)

Returns the value of attribute use_count

Returns:

  • (Object)

    the current value of use_count



5
6
7
# File 'lib/robot_lab/durable/entry.rb', line 5

def use_count
  @use_count
end

Class Method Details

.from_h(hash) ⇒ Object

Deserialize from a Hash (string or symbol keys).



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/robot_lab/durable/entry.rb', line 34

def self.from_h(hash)
  h = hash.transform_keys(&:to_s)
  new(
    content:    h["content"],
    reasoning:  h["reasoning"],
    category:   h["category"]&.to_sym,
    domain:     h["domain"],
    confidence: h["confidence"].to_f,
    use_count:  h["use_count"].to_i,
    created_at: h["created_at"],
    updated_at: h["updated_at"]
  )
end

Instance Method Details

#confirmObject

Return a new Entry with confidence incremented and use_count bumped.



10
11
12
13
14
15
16
17
# File 'lib/robot_lab/durable/entry.rb', line 10

def confirm
  new_confidence = [confidence + CONFIDENCE_INCREMENT, MAX_CONFIDENCE].min
  with(
    confidence: new_confidence.round(10),
    use_count:  use_count + 1,
    updated_at: Time.now.iso8601
  )
end

#to_hObject

Serialize to a plain Hash with string keys (safe for YAML round-trip).



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/robot_lab/durable/entry.rb', line 20

def to_h
  {
    "content"    => content,
    "reasoning"  => reasoning,
    "category"   => category.to_s,
    "domain"     => domain,
    "confidence" => confidence,
    "use_count"  => use_count,
    "created_at" => created_at,
    "updated_at" => updated_at
  }
end