Class: Anki::Deck
- Inherits:
-
Object
- Object
- Anki::Deck
- Defined in:
- lib/ankirb/anki/deck.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #[](id) ⇒ Object
-
#add_card(card) ⇒ Object
adds a card to the deck.
-
#add_card_with_inversion(card) ⇒ Object
adds a card, and then inserts the inverted version of the card immediately after.
-
#add_inversions ⇒ Object
add inverted versions of the cards at the end of the deck.
-
#initialize(name) ⇒ Deck
constructor
A new instance of Deck.
- #initialize_cards ⇒ Object
- #initialize_copy(orig) ⇒ Object
-
#invert! ⇒ Object
invert the faces of every card in place.
Constructor Details
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
4 5 6 |
# File 'lib/ankirb/anki/deck.rb', line 4 def cards @cards end |
#desc ⇒ Object
Returns the value of attribute desc.
3 4 5 |
# File 'lib/ankirb/anki/deck.rb', line 3 def desc @desc end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/ankirb/anki/deck.rb', line 4 def id @id end |
#name ⇒ Object
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_inversions ⇒ Object
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_cards ⇒ Object
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 |