class NoteBook
Attributes
preferences[R]
Public Class Methods
new(prefs)
click to toggle source
# File lib/models/note_book.rb, line 11 def initialize(prefs) @preferences = prefs end
Public Instance Methods
find(glob)
click to toggle source
# File lib/models/note_book.rb, line 31 def find(glob) return [] if glob.nil? || glob.empty? cmd = find_commandify(glob) found = `#{cmd}` return found.nil? ? found : found.split end
list(path)
click to toggle source
# File lib/models/note_book.rb, line 15 def list(path) path = path || '' notes_path = File.join(@preferences.notes_dir, path) system("tree #{notes_path}") end
new_note(path)
click to toggle source
# File lib/models/note_book.rb, line 25 def new_note(path) full_path = File.join(@preferences.notes_dir, path) full_path += '.' + @preferences.extension if File.extname(full_path).empty? Note.touch(full_path) end
on_run(glob)
click to toggle source
# File lib/models/note_book.rb, line 46 def on_run(glob) open_notes(glob) end
open_notes(glob)
click to toggle source
# File lib/models/note_book.rb, line 38 def open_notes(glob) enter_dir! found = find(glob)[0] found = './' if found.nil? system("#{@preferences.editor} #{found}") leave_dir! end
search(regex)
click to toggle source
# File lib/models/note_book.rb, line 21 def search(regex) system("grep --color=always -r #{@preferences.notes_dir} -e #{regex}") end
version()
click to toggle source
# File lib/models/note_book.rb, line 50 def version return PeterNotes::VERSION end
Private Instance Methods
enter_dir!()
click to toggle source
# File lib/models/note_book.rb, line 56 def enter_dir! @cur_dir = Dir.pwd Dir.chdir(@preferences.notes_dir) end
find_commandify(glob)
click to toggle source
# File lib/models/note_book.rb, line 65 def find_commandify(glob) glob = Glob.new(glob) glob_path, glob_file = glob.fuzzified cmd = "find \"#{@preferences.notes_dir}\" -name \"#{glob_file}\"" cmd += " | grep -e \"#{glob_path}\"" unless glob_path.nil? return cmd end
leave_dir!()
click to toggle source
# File lib/models/note_book.rb, line 61 def leave_dir! Dir.chdir(@cur_dir) end