Class: NoteBook

Inherits:
ConsoleApp show all
Defined in:
lib/models/note_book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConsoleApp

#run

Constructor Details

#initialize(prefs) ⇒ NoteBook

Returns a new instance of NoteBook.



11
12
13
# File 'lib/models/note_book.rb', line 11

def initialize(prefs)
  @preferences = prefs
end

Instance Attribute Details

#preferencesObject (readonly)

Returns the value of attribute preferences.



9
10
11
# File 'lib/models/note_book.rb', line 9

def preferences
  @preferences
end

Instance Method Details

#find(glob) ⇒ Object



31
32
33
34
35
36
# 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) ⇒ Object



15
16
17
18
19
# 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) ⇒ Object



25
26
27
28
29
# 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) ⇒ Object



46
47
48
# File 'lib/models/note_book.rb', line 46

def on_run(glob)
  open_notes(glob)
end

#open_notes(glob) ⇒ Object



38
39
40
41
42
43
44
# 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) ⇒ Object



21
22
23
# File 'lib/models/note_book.rb', line 21

def search(regex)
  system("grep --color=always -r #{@preferences.notes_dir} -e #{regex}")
end

#versionObject



50
51
52
# File 'lib/models/note_book.rb', line 50

def version
  return PeterNotes::VERSION
end