Class: RubyLLM::Registry::Comparison
- Inherits:
-
Object
- Object
- RubyLLM::Registry::Comparison
- Defined in:
- lib/ruby_llm/registry/comparison.rb
Overview
Represents a comparison between two prompt revisions.
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #body_diff ⇒ Object
- #changed? ⇒ Boolean
- #changed_fields ⇒ Object
-
#initialize(left, right) ⇒ Comparison
constructor
A new instance of Comparison.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(left, right) ⇒ Comparison
Returns a new instance of Comparison.
9 10 11 12 13 |
# File 'lib/ruby_llm/registry/comparison.rb', line 9 def initialize(left, right) @left = left @right = right @changes = build_changes end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
7 8 9 |
# File 'lib/ruby_llm/registry/comparison.rb', line 7 def changes @changes end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
7 8 9 |
# File 'lib/ruby_llm/registry/comparison.rb', line 7 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
7 8 9 |
# File 'lib/ruby_llm/registry/comparison.rb', line 7 def right @right end |
Instance Method Details
#body_diff ⇒ Object
23 24 25 |
# File 'lib/ruby_llm/registry/comparison.rb', line 23 def body_diff DiffLines.new(left.body.to_s, right.body.to_s).to_s end |
#changed? ⇒ Boolean
15 16 17 |
# File 'lib/ruby_llm/registry/comparison.rb', line 15 def changed? changes.any? end |
#changed_fields ⇒ Object
19 20 21 |
# File 'lib/ruby_llm/registry/comparison.rb', line 19 def changed_fields changes.keys end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ruby_llm/registry/comparison.rb', line 27 def to_h { left: snapshot(left), right: snapshot(right), changes: changes, body_diff: body_diff } end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ruby_llm/registry/comparison.rb', line 36 def to_s return "No changes" unless changed? parts = changes.map do |field, change| "#{field}: #{change[:from].inspect} -> #{change[:to].inspect}" end "#{parts.join('; ')}\n#{body_diff}" end |