Class: Anki::Deck

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Deck

Returns a new instance of Deck.



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

def initialize name
  @name = name
  @id = Anki::Helper.get_id
  initialize_cards
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



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

def cards
  @cards
end

#descObject

Returns the value of attribute desc.



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

def desc
  @desc
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#[](id) ⇒ Object



50
51
52
# File 'lib/ankirb/anki/deck.rb', line 50

def [] id
  @cards[id]
end

#add_card(card) ⇒ Object

adds a card to the deck



25
26
27
28
# File 'lib/ankirb/anki/deck.rb', line 25

def add_card card
  card.deck = self
  @cards[card.id] = card
end

#add_card_with_inversion(card) ⇒ Object

adds a card, and then inserts the inverted version of the card immediately after



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

def add_card_with_inversion card
  add_card card
  add_card card.invert
end

#add_inversionsObject

add inverted versions of the cards at the end of the deck



37
38
39
# File 'lib/ankirb/anki/deck.rb', line 37

def add_inversions
  @cards.values.each {|c| add_card c.invert }
end

#initialize_cardsObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ankirb/anki/deck.rb', line 12

def initialize_cards
  @cards = {}

  #change @cards#to_s to prevent recursive output via parent / child relationship
  class << @cards
    def to_s
      "#< #{self.keys.count} cards>"
    end
    alias_method :inspect, :to_s
  end
end

#initialize_copy(orig) ⇒ Object



54
55
56
57
58
# File 'lib/ankirb/anki/deck.rb', line 54

def initialize_copy(orig)
  super
  initialize_cards
  orig.cards.each { |c| add_card c.dup }
end

#invert!Object

invert the faces of every card in place



42
43
44
# File 'lib/ankirb/anki/deck.rb', line 42

def invert!
  @cards.values.each {|c| c.invert! }
end