Class: Notes
- Inherits:
-
ConsoleApp
- Object
- ConsoleApp
- Notes
- Defined in:
- lib/models/notes.rb
Instance Attribute Summary collapse
-
#editor ⇒ Object
readonly
Returns the value of attribute editor.
-
#notes_dir ⇒ Object
readonly
Returns the value of attribute notes_dir.
Instance Method Summary collapse
- #find(glob) ⇒ Object
-
#initialize(prefs) ⇒ Notes
constructor
A new instance of Notes.
- #list(path) ⇒ Object
- #on_run(glob) ⇒ Object
- #open_notes(glob) ⇒ Object
- #search(regex) ⇒ Object
- #version ⇒ Object
Methods inherited from ConsoleApp
Constructor Details
#initialize(prefs) ⇒ Notes
Returns a new instance of Notes.
8 9 10 11 |
# File 'lib/models/notes.rb', line 8 def initialize(prefs) @editor = prefs.editor @notes_dir = prefs.notes_dir end |
Instance Attribute Details
#editor ⇒ Object (readonly)
Returns the value of attribute editor.
6 7 8 |
# File 'lib/models/notes.rb', line 6 def editor @editor end |
#notes_dir ⇒ Object (readonly)
Returns the value of attribute notes_dir.
6 7 8 |
# File 'lib/models/notes.rb', line 6 def notes_dir @notes_dir end |
Instance Method Details
#find(glob) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/models/notes.rb', line 17 def find(glob) glob_path, glob_terminus = File.split(glob) glob_path.gsub!(File::SEPARATOR, '.*') cmd = "find \"#{@notes_dir}\" -name \"#{glob_terminus}\"" if glob_path != '.' # FILE::split breaks out . for bare file names cmd += " | grep -e \"#{glob_path}\"" end found = `#{cmd}` return found.split end |
#list(path) ⇒ Object
38 39 40 41 |
# File 'lib/models/notes.rb', line 38 def list(path) notes_path = File.join(@notes_dir, path) system("tree #{notes_path}") end |
#on_run(glob) ⇒ Object
43 44 45 |
# File 'lib/models/notes.rb', line 43 def on_run(glob) open_notes(glob) end |
#open_notes(glob) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/models/notes.rb', line 28 def open_notes(glob) enter_dir found = find(glob)[0] if found.nil? found = './' end system("#{@editor} #{found}") leave_dir end |
#search(regex) ⇒ Object
13 14 15 |
# File 'lib/models/notes.rb', line 13 def search(regex) system("grep --color=always -r #{@notes_dir} -e #{regex}") end |
#version ⇒ Object
47 48 49 |
# File 'lib/models/notes.rb', line 47 def version return PeterNotes::VERSION end |