Class: AnkiRecord::Anki2Database

Inherits:
Object
  • Object
show all
Defined in:
lib/anki_record/anki2_database/anki2_database.rb

Overview

Anki2Database represents the collection.anki2 Anki SQLite database in the Anki Package

This is not the database targeted by the Anki Record gem but it is part of the Anki package zip file.

Constant Summary collapse

FILENAME =
"collection.anki2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anki_packageObject (readonly)

:nodoc:



14
15
16
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 14

def anki_package
  @anki_package
end

#databaseObject (readonly)

:nodoc:



14
15
16
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 14

def database
  @database
end

Class Method Details

.create_new(anki_package:) ⇒ Object



16
17
18
19
20
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 16

def self.create_new(anki_package:)
  anki2_database = new
  anki2_database.create_initialize(anki_package:)
  anki2_database
end

.update_new(anki_package:) ⇒ Object



31
32
33
34
35
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 31

def self.update_new(anki_package:)
  anki2_database = new
  anki2_database.update_initialize(anki_package:)
  anki2_database
end

Instance Method Details

#create_initialize(anki_package:) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 22

def create_initialize(anki_package:)
  @anki_package = anki_package
  @database = SQLite3::Database.new("#{anki_package.tmpdir}/#{FILENAME}", options: {})
  database.execute_batch(ANKI_SCHEMA_DEFINITION)
  database.execute(INSERT_COLLECTION_ANKI_2_COL_RECORD)
  database.close
  database
end

#update_initialize(anki_package:) ⇒ Object



37
38
39
40
41
42
# File 'lib/anki_record/anki2_database/anki2_database.rb', line 37

def update_initialize(anki_package:)
  @anki_package = anki_package
  @database = SQLite3::Database.new("#{anki_package.tmpdir}/#{FILENAME}", options: {})
  database.close
  database
end