Class: RubyLLM::Registry::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/registry/comparison.rb

Overview

Represents a comparison between two prompt revisions.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changesObject (readonly)

Returns the value of attribute changes.



7
8
9
# File 'lib/ruby_llm/registry/comparison.rb', line 7

def changes
  @changes
end

#leftObject (readonly)

Returns the value of attribute left.



7
8
9
# File 'lib/ruby_llm/registry/comparison.rb', line 7

def left
  @left
end

#rightObject (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_diffObject



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

Returns:

  • (Boolean)


15
16
17
# File 'lib/ruby_llm/registry/comparison.rb', line 15

def changed?
  changes.any?
end

#changed_fieldsObject



19
20
21
# File 'lib/ruby_llm/registry/comparison.rb', line 19

def changed_fields
  changes.keys
end

#to_hObject



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_sObject



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