Class: NoteBook
- Inherits:
-
ConsoleApp
- Object
- ConsoleApp
- NoteBook
- Defined in:
- lib/models/note_book.rb
Instance Attribute Summary collapse
-
#preferences ⇒ Object
readonly
Returns the value of attribute preferences.
Instance Method Summary collapse
- #find(glob) ⇒ Object
-
#initialize(prefs) ⇒ NoteBook
constructor
A new instance of NoteBook.
- #list(path) ⇒ Object
- #new_note(path) ⇒ Object
- #on_run(glob) ⇒ Object
- #open_notes(glob) ⇒ Object
- #search(regex) ⇒ Object
- #version ⇒ Object
Methods inherited from ConsoleApp
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
#preferences ⇒ Object (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 |
#version ⇒ Object
50 51 52 |
# File 'lib/models/note_book.rb', line 50 def version return PeterNotes::VERSION end |