Class: RobotLab::Durable::Entry
- Inherits:
-
Data
- Object
- Data
- RobotLab::Durable::Entry
- Defined in:
- lib/robot_lab/durable/entry.rb
Constant Summary collapse
- CONFIDENCE_INCREMENT =
0.1- MAX_CONFIDENCE =
1.0
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#reasoning ⇒ Object
readonly
Returns the value of attribute reasoning.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#use_count ⇒ Object
readonly
Returns the value of attribute use_count.
Class Method Summary collapse
-
.from_h(hash) ⇒ Object
Deserialize from a Hash (string or symbol keys).
Instance Method Summary collapse
-
#confirm ⇒ Object
Return a new Entry with confidence incremented and use_count bumped.
-
#to_h ⇒ Object
Serialize to a plain Hash with string keys (safe for YAML round-trip).
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def category @category end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def confidence @confidence end |
#content ⇒ Object (readonly)
Returns the value of attribute content
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def domain @domain end |
#reasoning ⇒ Object (readonly)
Returns the value of attribute reasoning
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def reasoning @reasoning end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at
5 6 7 |
# File 'lib/robot_lab/durable/entry.rb', line 5 def updated_at @updated_at end |
#use_count ⇒ Object (readonly)
Returns the value of attribute 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
#confirm ⇒ Object
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_h ⇒ Object
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 |