class NoteCreator
Public Class Methods
new(notebook, title, notebook_path, workspace_path)
click to toggle source
# File lib/notes_cli/services/note_creator.rb, line 6 def initialize(notebook, title, notebook_path, workspace_path) @notebook = notebook @title = title.join('_') @notebook_path = notebook_path @workspace_path = workspace_path end
Public Instance Methods
call()
click to toggle source
# File lib/notes_cli/services/note_creator.rb, line 13 def call return unless notebook_exists?(@notebook) || create?('notebook') handle_errors create_note notify end
Private Instance Methods
create_note()
click to toggle source
# File lib/notes_cli/services/note_creator.rb, line 28 def create_note FileUtils.mkdir_p(@notebook_path) FileUtils.cd(@notebook_path) FileUtils.touch("#{@title}.md") FileUtils.cd(@workspace_path) end
handle_errors()
click to toggle source
# File lib/notes_cli/services/note_creator.rb, line 23 def handle_errors raise ArgumentError, 'no notebook specified' if !@notebook || @notebook.empty? raise ArgumentError, 'no note title specified' if !@title || @title.empty? end
notify()
click to toggle source
# File lib/notes_cli/services/note_creator.rb, line 35 def notify puts File.basename(@workspace_path) puts '----------------' puts "Added '#{@title}' to your #{@notebook} notebook" puts File.join(@notebook_path, "#{@title}.md") end