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
Methods inherited from ConsoleApp
Constructor Details
#initialize(prefs) ⇒ Notes
Returns a new instance of Notes.
7 8 9 10 |
# File 'lib/models/notes.rb', line 7 def initialize(prefs) @editor = prefs.editor @notes_dir = prefs.notes_dir end |
Instance Attribute Details
#editor ⇒ Object (readonly)
Returns the value of attribute editor.
5 6 7 |
# File 'lib/models/notes.rb', line 5 def editor @editor end |
#notes_dir ⇒ Object (readonly)
Returns the value of attribute notes_dir.
5 6 7 |
# File 'lib/models/notes.rb', line 5 def notes_dir @notes_dir end |
Instance Method Details
#find(glob) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/models/notes.rb', line 16 def find(glob) parsed = glob.split('/') glob_terminus = parsed.pop glob_path = parsed.join('/') cmd = "find \"#{@notes_dir}\" -name \"#{glob_terminus}\"" if glob_path != '' cmd += " | grep \"#{glob_path}\"" end found = `#{cmd}` return found.split end |
#list(path) ⇒ Object
38 39 40 |
# File 'lib/models/notes.rb', line 38 def list(path) system("tree #{@notes_dir}/#{path}") end |
#on_run(glob) ⇒ Object
42 43 44 |
# File 'lib/models/notes.rb', line 42 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
12 13 14 |
# File 'lib/models/notes.rb', line 12 def search(regex) system("grep --color=always -r #{@notes_dir} -e #{regex}") end |