NoteType represents an Anki note type (also called a model).
- A
- F
- N
- S
Constants
| NOTE_TYPES_WITHOUT_TAGS_AND_VERS_VALUES | = | ["Basic", "Basic (and reversed card)", "Basic (optional reversed card)", "Basic (type in the answer)"].freeze |
Class Public methods
new(anki21_database:, name: nil, args: nil) Link
Instantiates a new note type belonging to anki21_database with name name
Source: show
# File lib/anki_record/note_type/note_type.rb, line 24 def initialize(anki21_database:, name: nil, args: nil) raise ArgumentError unless (name && args.nil?) || (args && args["name"]) @anki21_database = anki21_database if args setup_note_type_instance_variables_from_existing(args:) else setup_instance_variables_for_new_note_type(name:) end @anki21_database.add_note_type self end
Instance Public methods
allowed_card_template_answer_format_field_names() Link
Returns allowed field_name values in {{field_name}} in the answer format.
Source: show
# File lib/anki_record/note_type/note_type.rb, line 92 def allowed_card_template_answer_format_field_names allowed_card_template_question_format_field_names + ["FrontSide"] end
allowed_card_template_question_format_field_names() Link
Returns allowed field_name values in {{field_name}} in the question format.
Source: show
# File lib/anki_record/note_type/note_type.rb, line 85 def allowed_card_template_question_format_field_names allowed = field_names_in_order cloze ? allowed + field_names_in_order.map { |field_name| "cloze:#{field_name}" } : allowed end
field_names_in_order() Link
Returns an array of the note type’s fields’ names ordered by field ordinal values.
Source: show
# File lib/anki_record/note_type/note_type.rb, line 65 def field_names_in_order @note_fields.sort_by(&:ordinal_number).map(&:name) end
find_card_template_by(name:) Link
Returns the note type object’s card template with name name or nil if it is not found
Source: show
# File lib/anki_record/note_type/note_type.rb, line 59 def find_card_template_by(name:) card_templates.find { |template| template.name == name } end
save() Link
Saves the note type to the collection.anki21 database
Source: show
# File lib/anki_record/note_type/note_type.rb, line 40 def save collection_models_hash = anki21_database.models_json collection_models_hash[@id] = to_h sql = "update col set models = ? where id = ?" anki21_database.prepare(sql).execute([JSON.generate(collection_models_hash), anki21_database.collection.id]) end