Class: LLMed::Application::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/llmed/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshot_file) ⇒ Snapshot

Returns a new instance of Snapshot.



67
68
69
70
# File 'lib/llmed/application.rb', line 67

def initialize(snapshot_file)
  @snapshot_file = snapshot_file
  @contexts = []
end

Instance Attribute Details

#snapshot_fileObject (readonly)

Returns the value of attribute snapshot_file.



65
66
67
# File 'lib/llmed/application.rb', line 65

def snapshot_file
  @snapshot_file
end

Instance Method Details

#diff(other_contexts) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/llmed/application.rb', line 82

def diff(other_contexts)
  diffs = {}
  other_contexts.each do |other_ctx|
    current_ctx = @contexts[other_ctx.name]
    result = line_diff(current_ctx['message'], other_ctx.raw)
    # omit not changes
    if !result.all?{|op, line| op == '=:'}
      diffs[other_ctx.name] = result
    end
  end

  diffs
end

#refresh(contexts) ⇒ Object



77
78
79
80
# File 'lib/llmed/application.rb', line 77

def refresh(contexts)
  @contexts = contexts.map{ |ctx| [ctx.name, {'name' => ctx.name, 'message' => ctx.raw}]}.to_h
  dump
end

#sync(default) ⇒ Object



72
73
74
75
# File 'lib/llmed/application.rb', line 72

def sync(default)
  load(default)
  dump
end