Class: Anki::Importer::Fact
- Inherits:
-
Object
- Object
- Anki::Importer::Fact
- Defined in:
- lib/anki/importer/fact.rb
Overview
An association tested by flash cards.
Instance Attribute Summary collapse
-
#anki_id ⇒ Object
readonly
Unique ID in the facts table.
-
#created_at ⇒ Object
readonly
Fact creation time.
-
#fields ⇒ Object
readonly
Maps Fields with their values.
-
#model ⇒ Object
readonly
The model that this field belongs to.
-
#modified_at ⇒ Object
readonly
Fact modification time.
-
#tags ⇒ Object
readonly
Assigned in the Anki UI.
Class Method Summary collapse
-
.from_db(deck_db, deck) ⇒ Object
Reads the models from an Anki deck.
Instance Method Summary collapse
-
#initialize(anki_id, model, tags, created_at, modified_at) ⇒ Fact
constructor
:nodoc: private.
Constructor Details
#initialize(anki_id, model, tags, created_at, modified_at) ⇒ Fact
:nodoc: private
49 50 51 52 53 54 55 56 |
# File 'lib/anki/importer/fact.rb', line 49 def initialize(anki_id, model, , created_at, modified_at) @anki_id = anki_id @model = model @tags = @created_at = created_at @modified_at = modified_at @fields = {} end |
Instance Attribute Details
#anki_id ⇒ Object (readonly)
Unique ID in the facts table.
19 20 21 |
# File 'lib/anki/importer/fact.rb', line 19 def anki_id @anki_id end |
#created_at ⇒ Object (readonly)
Fact creation time.
11 12 13 |
# File 'lib/anki/importer/fact.rb', line 11 def created_at @created_at end |
#fields ⇒ Object (readonly)
Maps Fields with their values.
16 17 18 |
# File 'lib/anki/importer/fact.rb', line 16 def fields @fields end |
#model ⇒ Object (readonly)
The model that this field belongs to.
21 22 23 |
# File 'lib/anki/importer/fact.rb', line 21 def model @model end |
#modified_at ⇒ Object (readonly)
Fact modification time.
13 14 15 |
# File 'lib/anki/importer/fact.rb', line 13 def modified_at @modified_at end |
#tags ⇒ Object (readonly)
Assigned in the Anki UI. Space-separated string.
9 10 11 |
# File 'lib/anki/importer/fact.rb', line 9 def @tags end |
Class Method Details
.from_db(deck_db, deck) ⇒ Object
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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, , t_created, t_modified| self.new anki_id, deck.models_by_id[model_id], , 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 |