Class: GNote::Tags
- Inherits:
-
Object
- Object
- GNote::Tags
- Defined in:
- lib/gnote/tags.rb
Class Method Summary collapse
Instance Method Summary collapse
- #concat_tags ⇒ Object
- #generate_tags(file) ⇒ Object
- #sort(content) ⇒ Object
-
#tags ⇒ Object
task.
-
#watch ⇒ Object
task.
Class Method Details
.tags ⇒ Object
11 12 13 |
# File 'lib/gnote/tags.rb', line 11 def Tags.new. end |
.watch ⇒ Object
7 8 9 |
# File 'lib/gnote/tags.rb', line 7 def watch Tags.new.watch end |
Instance Method Details
#concat_tags ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gnote/tags.rb', line 29 def content = "" Pa.each_r(Rc.p.) {|p| content << File.read(p.p) } content = sort(content) content = <<-EOF !_TAG_FILE_SORTED\t1 #{content} EOF File.write "#{Rc.p.note}/tags", content end |
#generate_tags(file) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/gnote/tags.rb', line 19 def (file) content = "" File.read("#{Rc.p.note}/#{file}").scan(/∗([^\n ]+)∗/) {|(id)| content << "#{id}\t#{file}\t/∗#{id}∗\n" } File.write "#{Rc.p.}/#{file}", content, :mkdir => true end |
#sort(content) ⇒ Object
46 47 48 49 50 |
# File 'lib/gnote/tags.rb', line 46 def sort(content) content = content.split(/\n/) content = content.sort_by{|v| v.split(/\t/)[0]} content.join("\n") + "\n" end |
#tags ⇒ Object
task
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gnote/tags.rb', line 53 def Pa.empty_dir Rc.p. Pa.each_r(Rc.p.note) {|p| next if skip_file(p.rel) (p.rel) } end |
#watch ⇒ Object
task
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gnote/tags.rb', line 66 def watch notifier = INotify::Notifier.new notifier.watch(Rc.p.note.p, :modify, :delete, :recursive) { |e| file = Pa(e.name) # "ds/pa.gnote" if skip_file(file) # skip else if e.flags.include?(:modify) GNote.ui.debug "MODIFY #{file}" (file) elsif e.flags.include?(:delete) GNote.ui.debug "DELETE #{file}" Pa.rm "#{Rc.p.}/#{file}" end end } GNote.ui.say ">> BEGIN WATCH AT #{Rc.p.note}" notifier.run end |