Class: Anki::Deck
- Inherits:
-
Object
- Object
- Anki::Deck
- Defined in:
- lib/anki/deck.rb
Instance Attribute Summary collapse
-
#card_data ⇒ Object
Returns the value of attribute card_data.
Instance Method Summary collapse
- #generate_deck(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Deck
constructor
A new instance of Deck.
Constructor Details
#initialize(options = {}) ⇒ Deck
Returns a new instance of Deck.
6 7 8 |
# File 'lib/anki/deck.rb', line 6 def initialize( = {}) @card_data = .delete(:card_data) end |
Instance Attribute Details
#card_data ⇒ Object
Returns the value of attribute card_data.
4 5 6 |
# File 'lib/anki/deck.rb', line 4 def card_data @card_data end |
Instance Method Details
#generate_deck(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/anki/deck.rb', line 10 def generate_deck( = {}) raise ArgumentError, "card_data should be an array of hashes" if !self.card_data.is_a?(Array) raise ArgumentError, "You need card data." if self.card_data.empty? anki_string = self.card_data.map { |card| "#{card.keys.first};#{card.values.first}" }.compact.join("\n") create_file(anki_string, [:file]) if [:file] anki_string end |