Module: AnkiConnect::Client::Cards

Included in:
AnkiConnect::Client
Defined in:
lib/anki_connect/cards.rb

Overview

Methods to query, modify, suspend, and manage individual flashcards.

Instance Method Summary collapse

Instance Method Details

#answer_cards(answers) ⇒ Array<Boolean>

Answers cards programmatically.

Parameters:

  • answers (Array<Hash>)

    Array of { cardId:, ease: } (1=Again, 2=Hard, 3=Good, 4=Easy)

Returns:

  • (Array<Boolean>)

    Array indicating if each card exists



136
137
138
# File 'lib/anki_connect/cards.rb', line 136

def answer_cards(answers)
  request(:answerCards, answers: answers)
end

#due?(card_ids) ⇒ Boolean+

Checks if cards are due for review.

Parameters:

  • card_ids (Integer, Array<Integer>)

    Single card ID or array

Returns:

  • (Boolean, Array<Boolean>)

    Boolean for single, array for multiple



67
68
69
70
71
72
73
# File 'lib/anki_connect/cards.rb', line 67

def due?(card_ids)
  if card_ids.is_a?(Array)
    request(:areDue, cards: card_ids)
  else
    request(:areDue, cards: [card_ids]).first
  end
end

#forget_cards(card_ids) ⇒ nil

Resets cards to “new” status.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (nil)


120
121
122
# File 'lib/anki_connect/cards.rb', line 120

def forget_cards(card_ids)
  request(:forgetCards, cards: card_ids)
end

#get_cards(card_ids) ⇒ Array<Hash>

Gets detailed information about cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Array<Hash>)

    Array of card objects



112
113
114
# File 'lib/anki_connect/cards.rb', line 112

def get_cards(card_ids)
  request(:cardsInfo, cards: card_ids)
end

#get_cards_mod_time(card_ids) ⇒ Array<Hash>

Gets modification times for cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Array<Hash>)

    Array of objects with cardId and mod



104
105
106
# File 'lib/anki_connect/cards.rb', line 104

def get_cards_mod_time(card_ids)
  request(:cardsModTime, cards: card_ids)
end

#get_ease_factors(card_ids) ⇒ Array<Integer>

Gets ease factors for cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Array<Integer>)

    Array of ease factor values



11
12
13
# File 'lib/anki_connect/cards.rb', line 11

def get_ease_factors(card_ids)
  request(:getEaseFactors, cards: card_ids)
end

#get_intervals(card_ids, complete: false) ⇒ Array<Integer>+

Gets intervals for cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

  • complete (Boolean) (defaults to: false)

    If true, returns all intervals

Returns:

  • (Array<Integer>, Array<Array<Integer>>)

    Intervals



80
81
82
# File 'lib/anki_connect/cards.rb', line 80

def get_intervals(card_ids, complete: false)
  request(:getIntervals, cards: card_ids, complete: complete)
end

#get_note_ids(card_ids) ⇒ Array<Integer>

Converts card IDs to their parent note IDs.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Array<Integer>)

    Array of note IDs



96
97
98
# File 'lib/anki_connect/cards.rb', line 96

def get_note_ids(card_ids)
  request(:cardsToNotes, cards: card_ids)
end

#relearn_cards(card_ids) ⇒ nil

Makes cards enter “relearning” state.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (nil)


128
129
130
# File 'lib/anki_connect/cards.rb', line 128

def relearn_cards(card_ids)
  request(:relearnCards, cards: card_ids)
end

#search_cards(query) ⇒ Array<Integer>

Searches for cards matching a query.

Parameters:

  • query (String)

    Anki search query string

Returns:

  • (Array<Integer>)

    Array of card IDs



88
89
90
# File 'lib/anki_connect/cards.rb', line 88

def search_cards(query)
  request(:findCards, query: query)
end

#set_due_date(card_ids, days) ⇒ Boolean

Sets due date for cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

  • days (String, Integer)

    Due date (0=today, 1!=tomorrow, 3-7=random range)

Returns:

  • (Boolean)

    true on success



145
146
147
# File 'lib/anki_connect/cards.rb', line 145

def set_due_date(card_ids, days)
  request(:setDueDate, cards: card_ids, days: days)
end

#set_ease_factors(card_ids, factors) ⇒ Array<Boolean>

Sets ease factors for cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

  • factors (Array<Integer>)

    Array of ease factor values

Returns:

  • (Array<Boolean>)

    Array indicating success for each card



20
21
22
# File 'lib/anki_connect/cards.rb', line 20

def set_ease_factors(card_ids, factors)
  request(:setEaseFactors, cards: card_ids, easeFactors: factors)
end

#suspend_cards(card_ids) ⇒ Boolean

Suspends cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Boolean)

    true if at least one card wasn’t already suspended



39
40
41
# File 'lib/anki_connect/cards.rb', line 39

def suspend_cards(card_ids)
  request(:suspend, cards: card_ids)
end

#suspended?(card_ids) ⇒ Boolean, Array<Boolean, nil>

Checks suspension status for cards.

Parameters:

  • card_ids (Integer, Array<Integer>)

    Single card ID or array

Returns:

  • (Boolean, Array<Boolean, nil>)

    Boolean for single, array for multiple



55
56
57
58
59
60
61
# File 'lib/anki_connect/cards.rb', line 55

def suspended?(card_ids)
  if card_ids.is_a?(Array)
    request(:areSuspended, cards: card_ids)
  else
    request(:suspended, card: card_ids)
  end
end

#unsuspend_cards(card_ids) ⇒ Boolean

Unsuspends cards.

Parameters:

  • card_ids (Array<Integer>)

    Array of card IDs

Returns:

  • (Boolean)

    true if at least one card was previously suspended



47
48
49
# File 'lib/anki_connect/cards.rb', line 47

def unsuspend_cards(card_ids)
  request(:unsuspend, cards: card_ids)
end

#update_card(card_id, fields, warning_check: false) ⇒ Array<Boolean>

Sets specific database values for a single card.

Parameters:

  • card_id (Integer)

    Card ID

  • fields (Hash)

    Database field names to new values

  • warning_check (Boolean) (defaults to: false)

    Must be true for certain risky keys

Returns:

  • (Array<Boolean>)

    Array indicating success for each field



30
31
32
33
# File 'lib/anki_connect/cards.rb', line 30

def update_card(card_id, fields, warning_check: false)
  request(:setSpecificValueOfCard, card: card_id, keys: fields.keys, newValues: fields.values,
                                   warning_check: warning_check)
end