Class: AnkiRecord::CardTemplate

Inherits:
Object
  • Object
show all
Includes:
CardTemplateAttributes
Defined in:
lib/anki_record/card_template/card_template.rb

Overview

CardTemplate represents a card template of an Anki note type.

Instance Attribute Summary

Attributes included from CardTemplateAttributes

#answer_format, #browser_font_size, #browser_font_style, #name, #note_type, #ordinal_number, #question_format

Instance Method Summary collapse

Constructor Details

#initialize(note_type:, name: nil, args: nil) ⇒ CardTemplate

Instantiates a new card template with name name for the note type note_type.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/anki_record/card_template/card_template.rb', line 12

def initialize(note_type:, name: nil, args: nil)
  raise ArgumentError unless (name && args.nil?) || (args && args["name"])

  @note_type = note_type
  if args
    setup_card_template_instance_variables_from_existing(args:)
  else
    setup_card_template_instance_variables(name:)
  end

  @note_type.add_card_template self
end

Instance Method Details

#to_hObject

:nodoc:



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/anki_record/card_template/card_template.rb', line 25

def to_h # :nodoc:
  {
    name: @name,
    ord: @ordinal_number,
    qfmt: @question_format, afmt: @answer_format,
    bqfmt: @bqfmt,
    bafmt: @bafmt,
    did: @deck_id,
    bfont: @browser_font_style,
    bsize: @browser_font_size
  }
end