Module: AnkiConnect::Client::Notes
- Included in:
- AnkiConnect::Client
- Defined in:
- lib/anki_connect/notes.rb
Overview
Methods to create, update, query, and manage notes (which generate cards).
Instance Method Summary collapse
-
#add_note(deck_name:, model_name:, fields:, tags: [], media: nil, options: nil) ⇒ Integer?
Creates a new note.
-
#add_notes(notes) ⇒ Array<Integer, nil>
Creates multiple notes.
-
#add_tags(note_ids, tags) ⇒ nil
Adds tags to notes.
-
#all_tags ⇒ Array<String>
Gets all tags in collection.
-
#can_add_notes(notes, details: false) ⇒ Array<Boolean>, Array<Hash>
Checks if notes can be added.
-
#change_note_model(id, model_name:, fields:, tags:) ⇒ nil
Changes a note’s model type.
-
#clear_unused_tags ⇒ nil
Removes unused tags from collection.
-
#delete_notes(note_ids) ⇒ nil
Deletes notes and all associated cards.
-
#get_note_tags(note_id) ⇒ Array<String>
Gets tags for a note.
-
#get_notes(note_ids: nil, query: nil) ⇒ Array<Hash>
Gets detailed information about notes.
-
#get_notes_mod_time(note_ids) ⇒ Array<Hash>
Gets modification times for notes.
-
#remove_empty_notes ⇒ nil
Removes all empty notes.
-
#remove_tags(note_ids, tags) ⇒ nil
Removes tags from notes.
-
#replace_tag(from:, to:, note_ids: nil) ⇒ nil
Replaces a tag with another.
-
#search_notes(query) ⇒ Array<Integer>
Searches for notes matching a query.
-
#update_note(id, fields: nil, tags: nil, media: nil) ⇒ nil
Updates a note’s fields, tags, or media.
Instance Method Details
#add_note(deck_name:, model_name:, fields:, tags: [], media: nil, options: nil) ⇒ Integer?
Creates a new note.
16 17 18 19 20 21 |
# File 'lib/anki_connect/notes.rb', line 16 def add_note(deck_name:, model_name:, fields:, tags: [], media: nil, options: nil) note = { deckName: deck_name, modelName: model_name, fields: fields, tags: } note.merge!(media) if media note[:options] = if request(:addNote, note: note) end |
#add_notes(notes) ⇒ Array<Integer, nil>
Creates multiple notes.
27 28 29 |
# File 'lib/anki_connect/notes.rb', line 27 def add_notes(notes) request(:addNotes, notes: notes) end |
#add_tags(note_ids, tags) ⇒ nil
Adds tags to notes.
83 84 85 |
# File 'lib/anki_connect/notes.rb', line 83 def (note_ids, ) request(:addTags, notes: note_ids, tags: ) end |
#all_tags ⇒ Array<String>
Gets all tags in collection.
99 100 101 |
# File 'lib/anki_connect/notes.rb', line 99 def request(:getTags) end |
#can_add_notes(notes, details: false) ⇒ Array<Boolean>, Array<Hash>
Checks if notes can be added.
36 37 38 39 40 41 42 |
# File 'lib/anki_connect/notes.rb', line 36 def can_add_notes(notes, details: false) if details request(:canAddNotesWithErrorDetail, notes: notes) else request(:canAddNotes, notes: notes) end end |
#change_note_model(id, model_name:, fields:, tags:) ⇒ nil
Changes a note’s model type.
66 67 68 |
# File 'lib/anki_connect/notes.rb', line 66 def change_note_model(id, model_name:, fields:, tags:) request(:updateNoteModel, note: { id: id, modelName: model_name, fields: fields, tags: }) end |
#clear_unused_tags ⇒ nil
Removes unused tags from collection.
106 107 108 |
# File 'lib/anki_connect/notes.rb', line 106 def request(:clearUnusedTags) end |
#delete_notes(note_ids) ⇒ nil
Deletes notes and all associated cards.
156 157 158 |
# File 'lib/anki_connect/notes.rb', line 156 def delete_notes(note_ids) request(:deleteNotes, notes: note_ids) end |
#get_note_tags(note_id) ⇒ Array<String>
Gets tags for a note.
74 75 76 |
# File 'lib/anki_connect/notes.rb', line 74 def (note_id) request(:getNoteTags, note: note_id) end |
#get_notes(note_ids: nil, query: nil) ⇒ Array<Hash>
Gets detailed information about notes.
137 138 139 140 141 142 |
# File 'lib/anki_connect/notes.rb', line 137 def get_notes(note_ids: nil, query: nil) params = {} params[:notes] = note_ids if note_ids params[:query] = query if query request(:notesInfo, **params) end |
#get_notes_mod_time(note_ids) ⇒ Array<Hash>
Gets modification times for notes.
148 149 150 |
# File 'lib/anki_connect/notes.rb', line 148 def get_notes_mod_time(note_ids) request(:notesModTime, notes: note_ids) end |
#remove_empty_notes ⇒ nil
Removes all empty notes.
163 164 165 |
# File 'lib/anki_connect/notes.rb', line 163 def remove_empty_notes request(:removeEmptyNotes) end |
#remove_tags(note_ids, tags) ⇒ nil
Removes tags from notes.
92 93 94 |
# File 'lib/anki_connect/notes.rb', line 92 def (note_ids, ) request(:removeTags, notes: note_ids, tags: ) end |
#replace_tag(from:, to:, note_ids: nil) ⇒ nil
Replaces a tag with another.
116 117 118 119 120 121 122 |
# File 'lib/anki_connect/notes.rb', line 116 def replace_tag(from:, to:, note_ids: nil) if note_ids request(:replaceTags, notes: note_ids, tag_to_replace: from, replace_with_tag: to) else request(:replaceTagsInAllNotes, tag_to_replace: from, replace_with_tag: to) end end |
#search_notes(query) ⇒ Array<Integer>
Searches for notes matching a query.
128 129 130 |
# File 'lib/anki_connect/notes.rb', line 128 def search_notes(query) request(:findNotes, query: query) end |
#update_note(id, fields: nil, tags: nil, media: nil) ⇒ nil
Updates a note’s fields, tags, or media.
51 52 53 54 55 56 57 |
# File 'lib/anki_connect/notes.rb', line 51 def update_note(id, fields: nil, tags: nil, media: nil) note = { id: id } note[:fields] = fields if fields note[:tags] = if note.merge!(media) if media request(:updateNote, note: note) end |