Class: Til::NoteDeleter

Inherits:
Object
  • Object
show all
Includes:
Thor::Actions, Thor::Base
Defined in:
lib/til/note_deleter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(note) ⇒ NoteDeleter

Returns a new instance of NoteDeleter.



7
8
9
# File 'lib/til/note_deleter.rb', line 7

def initialize(note)
  @note = note
end

Instance Attribute Details

#noteObject (readonly)

Returns the value of attribute note.



5
6
7
# File 'lib/til/note_deleter.rb', line 5

def note
  @note
end

Instance Method Details

#deleteObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/til/note_deleter.rb', line 11

def delete
  begin
    choice = ask("Really delete \"#{note.title.bold}\" (in #{note.subject.bold})? (y/n)")
    if (choice == "y") || (choice == "yes")
      File.delete(note.path)
      puts "\"#{note.title.bold}\" deleted.".green
    else
      puts "\"#{note.title.bold}\" not deleted.".red
    end
  rescue Interrupt
    warn "\nAborted!"
    abort
  end
end