Class: Anki::APKGExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/ankirb/export/apkg.rb

Class Method Summary collapse

Class Method Details

.export(deck, path) ⇒ Object

exports the provided deck object to an apkg file at the specified path



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ankirb/export/apkg.rb', line 13

def self.export deck, path
  export_deck = deck.dup

  Dir.mktmpdir do |dir|
    db = DB.create File.join(dir,'collection.anki2')

    export_media export_deck, dir
    export_deck export_deck, db

    filename = export_deck.name + '.apkg'
    archive = Zip::File.open(File.join(dir,filename), Zip::File::CREATE)

    Dir.glob(File.join(dir,'*')).each do |file|
      archive.add( File.basename(file),file)
    end

    archive.close()

    FileUtils.move(File.join(dir,filename), path)
  end
end