class Anki::Importer::Fact

An association tested by flash cards.

Attributes

anki_id[R]

Unique ID in the facts table.

created_at[R]

Fact creation time.

fields[R]

Maps Fields with their values.

model[R]

The model that this field belongs to.

modified_at[R]

Fact modification time.

tags[R]

Assigned in the Anki UI. Space-separated string.

Public Class Methods

from_db(deck_db, deck) click to toggle source

Reads the models from an Anki deck.

Args:

deck_db:: a Sqlite3::Datbase
deck: the (under construction) Anki::Importer::Deck for deck_db

Returns an array of Field instances.

# File lib/anki/importer/fact.rb, line 30
def self.from_db(deck_db, deck)
  fact_query = 'SELECT id, modelId, tags, created, modified FROM facts'
  facts = deck_db.execute(fact_query).map do |anki_id, model_id, tags,
                                              t_created, t_modified|
    self.new anki_id, deck.models_by_id[model_id], tags, Time.at(t_created),
             Time.at(t_modified)
  end
  facts_by_id = facts.index_by(&:anki_id)
  
  field = 'SELECT factId, fieldModelId, value FROM fields'
  deck_db.execute(field) do |fact_id, field_model_id, value|
    fact = facts_by_id[fact_id]
    field = deck.fields_by_id[field_model_id]
    fact.fields[field] = value
  end
  facts
end