class Dotnotes::Application
Public Class Methods
new()
click to toggle source
# File lib/dotnotes.rb, line 10 def initialize @notes_path = ENV['HOME'] + '/.notes' end
Public Instance Methods
delete(filename)
click to toggle source
Delete a note filename is the name of the note
@example note.delete(name)
# File lib/dotnotes.rb, line 75 def delete filename file_path = @notes_path + "/" + filename if initialized?(file: filename) system("rm #{file_path}") else raise NoteNotExist end end
edit(filename)
click to toggle source
Edit a note filename is the name of the note
@example note.show(name)
# File lib/dotnotes.rb, line 56 def edit filename file_path = @notes_path + "/" + filename if initialized?(file: filename) system("vi #{file_path}") else raise NoteNotExist end end
find(keyword)
click to toggle source
Find a keyword in a note
# File lib/dotnotes.rb, line 85 def find keyword system("find #{@notes_path} -type f -print0 | xargs -0 grep -li #{keyword}") end
help()
click to toggle source
# File lib/dotnotes.rb, line 89 def help puts "" puts "Commands:" puts " note new {filename} # Create a new note with filename" puts " note show {filename} # Display a note" puts " note edit {filename} # Edit a note" puts " note delete {filename} # Delete a note" puts " note list # List all notes" puts " note find {keyword} # Check which files contain the keyword" puts " note help # Display this help" puts "" end
initialized?(p={})
click to toggle source
# File lib/dotnotes.rb, line 14 def initialized? p={} path = @notes_path + "/" + p[:file].to_s File.exists?(path) end
list()
click to toggle source
Show all notes
# File lib/dotnotes.rb, line 66 def list system("stat #{@notes_path}/* -c \"%y %s %n\"") unless Dir[@notes_path + "/*"].empty? end
new(filename)
click to toggle source
Create a new note in notes path filename is the name of the note
@example begin
note.new(name)
rescue NoteAlreadyExist
puts "the note already exist
rescue UninitializedNotesPath
puts "note.init must be run first"
end
# File lib/dotnotes.rb, line 30 def new filename Dir.mkdir @notes_path unless initialized? if initialized?(file: filename) raise NoteAlreadyExist else file = File.open(@notes_path + "/#{filename}", "w") system("vi #{file.path}") end end
show(filename)
click to toggle source
Display contents of an existing note filename is the name of the note
@example note.show(name)
# File lib/dotnotes.rb, line 46 def show filename file_path = @notes_path + "/" + filename system("cat #{file_path}") if initialized?(file: filename) end