Class: Noteman::NoteManager
- Inherits:
-
Object
- Object
- Noteman::NoteManager
- Includes:
- Config
- Defined in:
- lib/noteman/note_manager.rb
Constant Summary
Constants included from Config
Instance Attribute Summary collapse
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#result ⇒ Object
Returns the value of attribute result.
-
#tags ⇒ Object
Returns the value of attribute tags.
Attributes included from Config
Class Method Summary collapse
Instance Method Summary collapse
- #by_keywords(keywords) ⇒ Object
- #by_tags(tags) ⇒ Object
- #capture(input, link = nil) ⇒ Object
- #choose(notes) ⇒ Object
- #fork_editor(input = "") ⇒ Object
- #inbox ⇒ Object
-
#initialize ⇒ NoteManager
constructor
A new instance of NoteManager.
- #reset_filter ⇒ Object
- #search_by_fomular(name) ⇒ Object
Methods included from Config
Constructor Details
#initialize ⇒ NoteManager
Returns a new instance of NoteManager.
6 7 8 9 10 11 12 |
# File 'lib/noteman/note_manager.rb', line 6 def initialize @notes = [] Dir.chdir(File.(config['notes_in'])) Dir.glob("*.#{config['ends_with']}").each do |file| @notes << Note.new(file) end end |
Instance Attribute Details
#notes ⇒ Object
Returns the value of attribute notes.
4 5 6 |
# File 'lib/noteman/note_manager.rb', line 4 def notes @notes end |
#result ⇒ Object
Returns the value of attribute result.
4 5 6 |
# File 'lib/noteman/note_manager.rb', line 4 def result @result end |
#tags ⇒ Object
Returns the value of attribute tags.
4 5 6 |
# File 'lib/noteman/note_manager.rb', line 4 def @tags end |
Class Method Details
.search ⇒ Object
14 15 16 17 |
# File 'lib/noteman/note_manager.rb', line 14 def self.search @@manager = NoteManager.new unless defined? @@manager @@manager.reset_filter end |
Instance Method Details
#by_keywords(keywords) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/noteman/note_manager.rb', line 32 def by_keywords(keywords) if keywords && keywords.length > 0 @result.delete_if { |note| not note.contains? keywords } end self end |
#by_tags(tags) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/noteman/note_manager.rb', line 25 def () if && .length > 0 @result.delete_if { |note| not note. } end self end |
#capture(input, link = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/noteman/note_manager.rb', line 57 def capture(input, link=nil) if link content = "[#{input}](#{link})" else content = input end open(config['capture_to'], 'a') do |f| f << "#{content}\n" end end |
#choose(notes) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/noteman/note_manager.rb', line 72 def choose(notes) if notes.length > 1 notes.each_with_index do |note, i| puts "% 3d: %s" % [i, note.file] end print "> " num = STDIN.gets return false if num =~ /^[a-z ]*$/i chosen = notes[num.to_i] elsif notes.length == 1 chosen = notes[0] else chosen = false end chosen end |
#fork_editor(input = "") ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/noteman/note_manager.rb', line 105 def fork_editor(input="") tmpfile = Tempfile.new('note') File.open(tmpfile.path,'w+') do |f| f.puts input end pid = Process.fork { system("$EDITOR #{tmpfile.path}") } trap("INT") { Process.kill(9, pid) rescue Errno::ESRCH tmpfile.unlink tmpfile.close! exit 0 } Process.wait(pid) begin if $?.exitstatus == 0 input = IO.read(tmpfile.path) else raise "Cancelled" end ensure tmpfile.close tmpfile.unlink end input end |
#inbox ⇒ Object
68 69 70 |
# File 'lib/noteman/note_manager.rb', line 68 def inbox notes.select { |n| n.file == config['capture_to'] }.first end |
#reset_filter ⇒ Object
19 20 21 22 23 |
# File 'lib/noteman/note_manager.rb', line 19 def reset_filter @result = [] @result += @notes self end |
#search_by_fomular(name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/noteman/note_manager.rb', line 39 def search_by_fomular(name) fomular = config['fomular'][name] if fomular search = fomular['tags'].split(' ') keywords = fomular['keywords'].split(' ') if end if keywords by_keywords keywords end else puts "No such fomular defined #{name}." end self end |