Class: Anki::Importer::Field
- Inherits:
-
Object
- Object
- Anki::Importer::Field
- Defined in:
- lib/anki/importer/field.rb
Overview
Schema element for Anki facts.
Each model has multiple fields. Each fact obeys the schema set by fields.
Instance Attribute Summary collapse
-
#anki_id ⇒ Object
readonly
Unique ID in the fields table.
-
#description ⇒ Object
readonly
Generally empty.
-
#model ⇒ Object
readonly
The model that this field belongs to.
-
#name ⇒ Object
readonly
Name assigned in the Anki UI.
-
#numeric ⇒ Object
readonly
True if the field is a sort key (number to sort the cards by).
-
#required ⇒ Object
readonly
True if no empty field values are allowed.
-
#unique ⇒ Object
readonly
True if all facts must have unique values for the field.
Class Method Summary collapse
-
.from_db(deck_db, deck) ⇒ Object
Reads the fields from an Anki deck.
Instance Method Summary collapse
-
#initialize(anki_id, model, name, description, features, required, unique, numeric) ⇒ Field
constructor
:nodoc: private.
Constructor Details
#initialize(anki_id, model, name, description, features, required, unique, numeric) ⇒ Field
:nodoc: private
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/anki/importer/field.rb', line 44 def initialize(anki_id, model, name, description, features, required, unique, numeric) @anki_id = anki_id @model = model @name = name @description = description @features = features @required = required @unique = unique @numeric = numeric end |
Instance Attribute Details
#anki_id ⇒ Object (readonly)
Unique ID in the fields table.
23 24 25 |
# File 'lib/anki/importer/field.rb', line 23 def anki_id @anki_id end |
#description ⇒ Object (readonly)
Generally empty.
13 14 15 |
# File 'lib/anki/importer/field.rb', line 13 def description @description end |
#model ⇒ Object (readonly)
The model that this field belongs to.
25 26 27 |
# File 'lib/anki/importer/field.rb', line 25 def model @model end |
#name ⇒ Object (readonly)
Name assigned in the Anki UI.
11 12 13 |
# File 'lib/anki/importer/field.rb', line 11 def name @name end |
#numeric ⇒ Object (readonly)
True if the field is a sort key (number to sort the cards by).
20 21 22 |
# File 'lib/anki/importer/field.rb', line 20 def numeric @numeric end |
#required ⇒ Object (readonly)
True if no empty field values are allowed.
16 17 18 |
# File 'lib/anki/importer/field.rb', line 16 def required @required end |
#unique ⇒ Object (readonly)
True if all facts must have unique values for the field.
18 19 20 |
# File 'lib/anki/importer/field.rb', line 18 def unique @unique end |
Class Method Details
.from_db(deck_db, deck) ⇒ Object
Reads the fields 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.
34 35 36 37 38 39 40 41 |
# File 'lib/anki/importer/field.rb', line 34 def self.from_db(deck_db, deck) query = 'SELECT id, modelId, name, description, features, required, "unique", numeric FROM fieldModels ORDER BY ordinal' models = deck_db.execute(query).map do |anki_id, model_id, name, description, features, required, unique, numeric| self.new anki_id, deck.models_by_id[model_id], name, description, features, required == 1, unique == 1, numeric == 1 end end |