Class: Compose::EditProcessor

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/compose/edit_processor.rb

Constant Summary collapse

HISTORY_FILE =
'compose_history.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(edits) ⇒ EditProcessor

Returns a new instance of EditProcessor.



16
17
18
19
# File 'lib/compose/edit_processor.rb', line 16

def initialize(edits)
  @edits = edits
  @confirmed_edits = []
end

Instance Attribute Details

#editsObject (readonly)

Returns the value of attribute edits.



14
15
16
# File 'lib/compose/edit_processor.rb', line 14

def edits
  @edits
end

Instance Method Details

#process_editsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/compose/edit_processor.rb', line 21

def process_edits
  edits.each do |edit|
    if confirm_edit(edit[:edit])
      @confirmed_edits << edit[:edit]
    end
  end

  if @confirmed_edits.any?
    if ask('Do you want to apply all confirmed edits? (y/n)') == 'y'
      apply_confirmed_edits
    else
      puts 'All changes discarded.'
    end
  else
    puts 'No edits were confirmed.'
  end
end