Class: FuzzyNotes::Notes
- Inherits:
-
Object
- Object
- FuzzyNotes::Notes
- Includes:
- Logger
- Defined in:
- lib/fuzzy_notes/notes.rb
Defined Under Namespace
Modules: Defaults
Constant Summary collapse
- VALID_PARAMS =
[:log_level, :color, :editor, :note_paths, :valid_extensions, :keywords, :evernote_params].freeze
Constants included from Logger::Colors
Logger::Colors::CREATE_COLOR, Logger::Colors::DEFAULT_COLOR, Logger::Colors::DELETE_COLOR, Logger::Colors::EXPORT_COLOR, Logger::Colors::IMPORT_COLOR, Logger::Colors::NOTE_COLOR, Logger::Colors::NUMBER_COLOR, Logger::Colors::PATH_COLOR, Logger::Colors::USER_COLOR
Instance Attribute Summary collapse
-
#all_notes ⇒ Object
readonly
Returns the value of attribute all_notes.
Instance Method Summary collapse
-
#cat ⇒ Object
dump all matching notes to stdout.
-
#decrypt ⇒ Object
decrypt matching notes.
-
#edit ⇒ Object
edit all matching notes in EDITOR.
-
#encrypt ⇒ Object
encrypt matching notes.
- #evernote_sync ⇒ Object
-
#info ⇒ Object
view WC info for all/matching notes.
-
#initialize(params = {}) ⇒ Notes
constructor
A new instance of Notes.
- #list ⇒ Object
Methods included from Logger
Constructor Details
#initialize(params = {}) ⇒ Notes
Returns a new instance of Notes.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fuzzy_notes/notes.rb', line 23 def initialize(params = {}) parse_init_params(params) FuzzyNotes::Log.init_log(@log_level, @color) log.debug "init params: \n#{inspect_instance_vars}" @note_paths = prune_invalid_note_paths! finder = FuzzyNotes::FuzzyFinder.new(@note_paths, { :keywords => @keywords, :extensions => @valid_extensions, :full_text_search => params[:full_text_search] }) @all_notes, @matching_notes = finder.files_matching_extension, finder.files_matching_all @cipher = FuzzyNotes::Cipher.new end |
Instance Attribute Details
#all_notes ⇒ Object (readonly)
Returns the value of attribute all_notes.
21 22 23 |
# File 'lib/fuzzy_notes/notes.rb', line 21 def all_notes @all_notes end |
Instance Method Details
#cat ⇒ Object
dump all matching notes to stdout
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fuzzy_notes/notes.rb', line 39 def cat unless encrypted_notes.empty? print_notes(:encrypted => true) decrypted_notes = @cipher.decrypt_files(encrypted_notes) end matching_notes.each do |note_path| contents = \ if FuzzyNotes::Cipher.encrypted?(note_path) decrypted_notes.shift elsif FuzzyNotes::EvernoteSync.evernote?(note_path) FuzzyNotes::EvernoteSync.sanitize_evernote(note_path) else File.read(note_path) end if contents log.info "=== #{note_path} ===\n\n" puts "#{contents}\n" end end end |
#decrypt ⇒ Object
decrypt matching notes
104 105 106 107 108 109 110 |
# File 'lib/fuzzy_notes/notes.rb', line 104 def decrypt return if encrypted_notes.empty? print_notes(:encrypted => true) log.indent do @cipher.decrypt_files(encrypted_notes, :replace => true) end end |
#edit ⇒ Object
edit all matching notes in EDITOR
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fuzzy_notes/notes.rb', line 64 def edit notes_to_edit = \ unless encrypted_notes.empty? print_notes(:encrypted => true) decrypted_tempfiles = @cipher.decrypt_to_tempfiles(encrypted_notes) successfully_decrypted_files = decrypted_tempfiles.compact plaintext_notes + successfully_decrypted_files else plaintext_notes end # edit decrypted files unless notes_to_edit.empty? system("#{editor} #{bashify_note_paths(notes_to_edit)}") end # reencrypt decrypted notes unless encrypted_notes.empty? || successfully_decrypted_files.empty? log.info "#{CREATE_COLOR} re-encrypting edited notes:" tempfiles_notes = decrypted_tempfiles.zip(encrypted_notes) log.indent do tempfiles_notes.each do |(tmpfile, note_path)| log.info "#{PATH_COLOR} #{note_path}" if note_path end end log.indent { @cipher.encrypt_from_tempfiles(tempfiles_notes) } end end |
#encrypt ⇒ Object
encrypt matching notes
94 95 96 97 98 99 100 |
# File 'lib/fuzzy_notes/notes.rb', line 94 def encrypt return if plaintext_notes.empty? print_notes(:plaintext => true) log.indent do @cipher.encrypt_files(plaintext_notes, :replace => true) end end |
#evernote_sync ⇒ Object
123 124 125 126 |
# File 'lib/fuzzy_notes/notes.rb', line 123 def evernote_sync return unless evernote_params_found? FuzzyNotes::EvernoteSync.new(@evernote_params).sync end |
#info ⇒ Object
view WC info for all/matching notes
114 115 116 117 |
# File 'lib/fuzzy_notes/notes.rb', line 114 def info paths = bashify_note_paths(matching_notes(:all_if_empty => true)) puts `wc $(find #{paths} -type f)` end |
#list ⇒ Object
119 120 121 |
# File 'lib/fuzzy_notes/notes.rb', line 119 def list print_notes(:all_if_empty => true) end |