-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjournal_manager.rb
More file actions
35 lines (29 loc) · 899 Bytes
/
journal_manager.rb
File metadata and controls
35 lines (29 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative 'journal'
require 'tty-prompt'
# a file to manage which journal is opened
class JournalManager
def initialize
@current_journal = nil
end
def load_journal(filename)
@current_journal = Journal.new(filename)
@current_journal.load_from_file
@current_journal
end
def swap_journal(filename = nil)
@current_journal.save_to_file if @current_journal
# If no filename provided, prompt user
if filename.nil?
prompt = TTY::Prompt.new(active_color: :green)
journal_files = Dir.glob('data/*txt').map { |path| File.basename(path) }
if journal_files.empty?
puts 'No saved journals found. starting default My Journal'.yellow
filename = 'My Journal.txt'
else
filename = prompt.select('Select your journal', journal_files)
end
end
load_journal(filename)
end
attr_reader :current_journal
end