Class: RobotLab::Durable::Entry

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

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



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def category
  @category
end

#confidenceObject (readonly)

Returns the value of attribute confidence

Returns:

  • (Object)

    the current value of confidence



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain

Returns:

  • (Object)

    the current value of domain



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def domain
  @domain
end

#reasoningObject (readonly)

Returns the value of attribute reasoning

Returns:

  • (Object)

    the current value of reasoning



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def reasoning
  @reasoning
end

#updated_atObject (readonly)

Returns the value of attribute updated_at

Returns:

  • (Object)

    the current value of updated_at



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

def updated_at
  @updated_at
end

#use_countObject (readonly)

Returns the value of attribute use_count

Returns:

  • (Object)

    the current value of use_count



8
9
10
# File 'lib/robot_lab/durable/entry.rb', line 8

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