Class: Anki::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/ankirb/anki/card.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Card

Returns a new instance of Card.



6
7
8
9
10
11
12
# File 'lib/ankirb/anki/card.rb', line 6

def initialize options={}
  @front = CardFace.new(options[:front] || '')
  @back = CardFace.new(options[:back] || '')
  @tags = options[:tags] || []

  @id = Anki::Helper.get_id
end

Instance Attribute Details

#deckObject

Returns the value of attribute deck.



3
4
5
# File 'lib/ankirb/anki/card.rb', line 3

def deck
  @deck
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/ankirb/anki/card.rb', line 4

def id
  @id
end

#tagsObject

Returns the value of attribute tags.



3
4
5
# File 'lib/ankirb/anki/card.rb', line 3

def tags
  @tags
end

Instance Method Details

#backObject Also known as: answer



18
19
20
# File 'lib/ankirb/anki/card.rb', line 18

def back
  @back
end

#back=(value) ⇒ Object Also known as: answer=



48
49
50
51
52
53
54
# File 'lib/ankirb/anki/card.rb', line 48

def back= value
  if value.is_a? String
    @back.content = value
  else
    @back = value
  end
end

#frontObject Also known as: question



14
15
16
# File 'lib/ankirb/anki/card.rb', line 14

def front
  @front
end

#front=(value) ⇒ Object Also known as: question=



40
41
42
43
44
45
46
# File 'lib/ankirb/anki/card.rb', line 40

def front= value
  if value.is_a? String
    @front.content = value
  else
    @front = value
  end
end

#has_media?Boolean

is media attached to this card?

Returns:

  • (Boolean)


36
37
38
# File 'lib/ankirb/anki/card.rb', line 36

def has_media?
  !@front.media.empty? or !back.media.empty?
end

#initialize_copy(orig) ⇒ Object



56
57
58
59
60
# File 'lib/ankirb/anki/card.rb', line 56

def initialize_copy orig
  super
  @front = Marshal.load(Marshal.dump(orig.front))
  @back = Marshal.load(Marshal.dump(orig.back))
end

#invertObject

returns a new card with the front and back of the original inverted



23
24
25
26
27
28
# File 'lib/ankirb/anki/card.rb', line 23

def invert
  c = Anki::Card.new(front: @back.to_s, back: @front.to_s)
  c.front = @back.dup
  c.back = @front.dup
  c
end

#invert!Object

flips the front and back of this card



31
32
33
# File 'lib/ankirb/anki/card.rb', line 31

def invert!
  @front, @back = @back, @front
end