Class: Notes
Instance Method Summary collapse
-
#await_command(message = nil) ⇒ Object
/================================# REPL type thing # ================================/#.
-
#initialize(config) ⇒ Notes
constructor
A new instance of Notes.
- #run_command(action, params) ⇒ Object
Methods included from Commands
#config, #create, #delete, #help, #info, #list, #list_tags, #open, #peek, #search, #tag, #tags, #untag
Constructor Details
#initialize(config) ⇒ Notes
Returns a new instance of Notes.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cnote/notes.rb', line 11 def initialize(config) @config = config @index = 1 @notes = Hash.new notes = Dir[File.join(@config.note_path, "**/*")].select do |f| [".txt", ".md"].include?(File.extname(f)) end notes.each do |path| note = Note.new(path) note.index = @index @notes[@index] = note @index += 1 end @indent = notes.length.to_s.length + 2 set_filtered(@notes) end |
Instance Method Details
#await_command(message = nil) ⇒ Object
/================================#
REPL type thing #
================================/#
38 39 40 41 42 43 44 45 46 |
# File 'lib/cnote/notes.rb', line 38 def await_command( = nil) puts if print "#{@config.prompt} ".magenta input = STDIN.gets.chomp # Strip and process action, *params = input.strip.gsub(/\s{2,}/, " ").split(" ") run_command(action || "help", params) end |
#run_command(action, params) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cnote/notes.rb', line 48 def run_command(action, params) case action.downcase when "new", "create", "n", "c" create(params) when "edit", "open", "e", "o" open(params) when "delete", "d", "rm" delete(params) when "peek", "p" peek(params) when "tag", "t" tag(params) when "tags" (params) when "untag", "ut" untag(params) when "search", "find", "s", "f" search(params.join(" ")) when "list", "l", "ls" list when "info", "i" info(params) when "help", "h" help when "config", "conf" config(params) when "quit", "exit", "close", "q" exit else puts "Sorry, didn't quite get that..." help end await_command # Drop back to REPL end |