Class: AnkiRecord::Deck
- Inherits:
-
Object
- Object
- AnkiRecord::Deck
- Defined in:
- lib/anki_record/deck/deck.rb
Overview
Deck represents an Anki deck.
Instance Attribute Summary
Attributes included from DeckAttributes
#anki21_database, #deck_options_group, #description, #id, #last_modified_timestamp, #name
Instance Method Summary collapse
-
#initialize(anki21_database:, name: nil, args: nil) ⇒ Deck
constructor
Instantiates a new Deck object belonging to
anki21_database
with namename
. -
#inspect ⇒ Object
:nodoc: :nocov:.
-
#save ⇒ Object
Saves the deck to the collection.anki21 database.
-
#to_h ⇒ Object
:nodoc:.
Methods included from Helpers::TimeHelper
#milliseconds_since_epoch, #seconds_since_epoch
Constructor Details
#initialize(anki21_database:, name: nil, args: nil) ⇒ Deck
Instantiates a new Deck object belonging to anki21_database
with name name
.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/anki_record/deck/deck.rb', line 19 def initialize(anki21_database:, name: nil, args: nil) raise ArgumentError unless (name && args.nil?) || (args && args["name"]) @anki21_database = anki21_database if args setup_deck_instance_variables_from_existing(args:) else setup_deck_instance_variables(name:) end @anki21_database.add_deck self save if args end |
Instance Method Details
#inspect ⇒ Object
:nodoc: :nocov:
54 55 56 |
# File 'lib/anki_record/deck/deck.rb', line 54 def inspect "#<AnkiRecord::Deck:#{object_id} id: #{id} name: #{name} description: #{description}>" end |
#save ⇒ Object
Saves the deck to the collection.anki21 database.
35 36 37 38 39 40 |
# File 'lib/anki_record/deck/deck.rb', line 35 def save collection_decks_hash = anki21_database.decks_json collection_decks_hash[@id] = to_h sql = "update col set decks = ? where id = ?" anki21_database.prepare(sql).execute([JSON.generate(collection_decks_hash), anki21_database.collection.id]) end |
#to_h ⇒ Object
:nodoc:
42 43 44 45 46 47 48 49 50 |
# File 'lib/anki_record/deck/deck.rb', line 42 def to_h # :nodoc: { id: @id, mod: @last_modified_timestamp, name: @name, usn: @usn, lrnToday: @learn_today, revToday: @review_today, newToday: @new_today, timeToday: @time_today, collapsed: @collapsed_in_main_window, browserCollapsed: @collapsed_in_browser, desc: @description, dyn: @dyn, conf: @deck_options_group.id, extendNew: @extend_new, extendRev: @extend_review } end |