Class: AnkiRecord::Media

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

Overview

:nodoc:

Constant Summary collapse

FILENAME =
"media"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anki_packageObject (readonly)

Returns the value of attribute anki_package.



5
6
7
# File 'lib/anki_record/media/media.rb', line 5

def anki_package
  @anki_package
end

#media_fileObject (readonly)

Returns the value of attribute media_file.



5
6
7
# File 'lib/anki_record/media/media.rb', line 5

def media_file
  @media_file
end

Class Method Details

.create_new(anki_package:) ⇒ Object



9
10
11
12
13
# File 'lib/anki_record/media/media.rb', line 9

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

.update_new(anki_package:) ⇒ Object



23
24
25
26
27
# File 'lib/anki_record/media/media.rb', line 23

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

Instance Method Details

#create_initialize(anki_package:) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/anki_record/media/media.rb', line 15

def create_initialize(anki_package:)
  @anki_package = anki_package
  media_file_path = FileUtils.touch("#{anki_package.tmpdir}/#{FILENAME}")[0]
  @media_file = File.open(media_file_path, mode: "w")
  media_file.write("{}")
  media_file.close
end

#update_initialize(anki_package:) ⇒ Object



29
30
31
32
33
34
# File 'lib/anki_record/media/media.rb', line 29

def update_initialize(anki_package:)
  @anki_package = anki_package
  @media_file = File.open("#{anki_package.tmpdir}/#{FILENAME}", mode: "w")
  media_file.write("{}")
  media_file.close
end