Class: Rnote::Find
- Inherits:
-
Object
- Object
- Rnote::Find
- Defined in:
- lib/rnote/noun/note/find.rb
Constant Summary collapse
- MAX_RESULTS_PER_PAGE =
Warning Don’t take the Notes resulting from these searches and try to update them in Evernote they may not be fully populate, missing tags, or content. instead just use this list to display the note lists, or to get the guid and pull the whole note again.
10
Class Method Summary collapse
Instance Method Summary collapse
- #display_results(notes) ⇒ Object
- #fill_note(note) ⇒ Object
-
#find_cmd(options, args) ⇒ Object
runs the search displays it saves it.
-
#find_note(options, args) ⇒ Object
get the note to edit.
- #get_full_note(guid) ⇒ Object
-
#initialize(auth, persister) ⇒ Find
constructor
A new instance of Find.
-
#search(options, args) ⇒ Object
runs a search returns the results.
Constructor Details
#initialize(auth, persister) ⇒ Find
Returns a new instance of Find.
17 18 19 20 |
# File 'lib/rnote/noun/note/find.rb', line 17 def initialize(auth,persister) @auth = auth # auth instead of client so I can postpone connecting. @persister = persister end |
Class Method Details
.has_search_options(options) ⇒ Object
89 90 91 |
# File 'lib/rnote/noun/note/find.rb', line 89 def Find.() !! [:title] end |
.include_search_options(noun) ⇒ Object
84 85 86 87 |
# File 'lib/rnote/noun/note/find.rb', line 84 def Find.(noun) noun.desc "phrase to find in title of note" noun.flag :title end |
Instance Method Details
#display_results(notes) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/rnote/noun/note/find.rb', line 76 def display_results(notes) inc = 1 notes.each do |note| puts "#{inc}: #{note.title} - #{note.tagNames.join(', ')}\n#{note.summarize}\n\n" inc += 1 end end |
#fill_note(note) ⇒ Object
46 47 48 49 |
# File 'lib/rnote/noun/note/find.rb', line 46 def fill_note(note) note.content = @auth.client.note_store.getNoteContent(note.guid) note.tagNames = @auth.client.note_store.getNoteTagNames(note.guid) end |
#find_cmd(options, args) ⇒ Object
runs the search displays it saves it. returns nothing
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rnote/noun/note/find.rb', line 61 def find_cmd(,args) results = search(,args) if results.empty? @persister.save_last_search_guids([]) puts "no notes found" else guids = results.map { |note| note.guid } @persister.save_last_search_guids(guids) display_results(results) end end |
#find_note(options, args) ⇒ Object
get the note to edit. whether from options or last search result or interactively run a searching using the options and/or arguments use last search if it makes sense to do so. returns a note
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rnote/noun/note/find.rb', line 97 def find_note(,args) results = nil if args.length == 1 and not Find.() and args[0].match(/^\d{1,3}$/) # no search options, one argument, and its a small number # they are asking to pick from the last search results guids = @persister.get_last_search_guids guid = guids[args[0].to_i - 1] # the chosen note note = get_full_note(guid) results = [note] # fake a result set with it. else results = search(,args) end if results.length == 0 raise "no matching note found." elsif results.length == 1 return results[0] else if [:interactive] display_results(results) answer = ask 'Which note? ', Integer do |q| q.in = 1..results.length end results[answer - 1] else raise 'too many results. or try --interactive to select' end end end |
#get_full_note(guid) ⇒ Object
51 52 53 54 55 |
# File 'lib/rnote/noun/note/find.rb', line 51 def get_full_note(guid) note = @auth.client.note_store.getNote(guid,true,false,false,false) note.tagNames = @auth.client.note_store.getNoteTagNames(note.guid) note end |
#search(options, args) ⇒ Object
runs a search returns the results
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rnote/noun/note/find.rb', line 24 def search(,args) # process arguments into an evernote search query filter = Evernote::EDAM::NoteStore::NoteFilter.new filter.order = Evernote::EDAM::Type::NoteSortOrder::UPDATED if [:title] args << "intitle:'#{[:title]}'" end filter.words = args.join(' ') page = 0 notes = @auth.client.note_store.findNotes(filter,page * MAX_RESULTS_PER_PAGE,MAX_RESULTS_PER_PAGE).notes # we fully pouplate each note at search time # poor choice for performance, though notes.each do |note| fill_note(note) end notes end |