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 27 |
# File 'lib/models/notes.rb', line 17 def find(glob) return [] if glob.nil? || glob.empty? 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
39 40 41 42 43 |
# File 'lib/models/notes.rb', line 39 def list(path) path = path || '' notes_path = File.join(@notes_dir, path) system("tree #{notes_path}") end |
#on_run(glob) ⇒ Object
45 46 47 |
# File 'lib/models/notes.rb', line 45 def on_run(glob) open_notes(glob) end |
#open_notes(glob) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/models/notes.rb', line 29 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
49 50 51 |
# File 'lib/models/notes.rb', line 49 def version return PeterNotes::VERSION end |