Anki21Database
represents the collection.anki21 Anki SQLite database in the Anki Package
- F
- P
Instance Public methods
find_deck_by(name: nil, id: nil) Link
Returns the deck found by either name
or id
, or nil if it is not found.
Source: show
# File lib/anki_record/anki21_database/anki21_database.rb, line 83 def find_deck_by(name: nil, id: nil) if (id && name) || (id.nil? && name.nil?) raise ArgumentError, "You must pass either an id or name keyword argument to find_deck_by." end name ? find_deck_by_name(name:) : find_deck_by_id(id:) end
find_deck_options_group_by(id:) Link
Returns the deck options group object found by id
, or nil if it is not found.
Source: show
# File lib/anki_record/anki21_database/anki21_database.rb, line 94 def find_deck_options_group_by(id:) deck_options_groups.find { |deck_options_group| deck_options_group.id == id } end
find_note_by(sfld: nil, id: nil) Link
rubocop:disable Metrics/MethodLength
Returns the note found by either +sfld“ or id
, or nil if it is not found.
Source: show
# File lib/anki_record/anki21_database/anki21_database.rb, line 36 def find_note_by(sfld: nil, id: nil) if (id && sfld) || (id.nil? && sfld.nil?) raise ArgumentError, "You must pass either an id or sfld keyword argument to find_note_by." end note_cards_data = if id note_cards_data_for_note(id:) else note_cards_data_for_note(sfld:) end return nil unless note_cards_data AnkiRecord::Note.new(anki21_database: self, data: note_cards_data) end
find_note_type_by(name: nil, id: nil) Link
Returns the note type found by either name
or id
, or nil if it is not found.
Source: show
# File lib/anki_record/anki21_database/anki21_database.rb, line 72 def find_note_type_by(name: nil, id: nil) if (id && name) || (id.nil? && name.nil?) raise ArgumentError, "You must pass either an id or name keyword argument to find_note_type_by." end name ? find_note_type_by_name(name:) : find_note_type_by_id(id:) end
find_notes_by_exact_text_match(text:) Link
Returns an array of notes that have any field value matching text
Source: show
# File lib/anki_record/anki21_database/anki21_database.rb, line 54 def find_notes_by_exact_text_match(text:) return [] if text == "" like_matcher = "%#{text}%" note_datas = prepare("select * from notes where flds LIKE ?").execute([like_matcher]) note_datas.map do |note_data| id = note_data["id"] cards_data = prepare("select * from cards where nid = ?").execute([id]).to_a note_cards_data = { note_data:, cards_data: } AnkiRecord::Note.new(anki21_database: self, data: note_cards_data) end end