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.
-
#card_headers ⇒ Object
Returns the value of attribute card_headers.
-
#field_separator ⇒ Object
Returns the value of attribute field_separator.
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 9 10 |
# File 'lib/anki/deck.rb', line 6 def initialize( = {}) @card_headers = .delete(:card_headers) @card_data = .delete(:card_data) @field_separator = .delete(:field_separator) || ";" 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 |
#card_headers ⇒ Object
Returns the value of attribute card_headers.
4 5 6 |
# File 'lib/anki/deck.rb', line 4 def card_headers @card_headers end |
#field_separator ⇒ Object
Returns the value of attribute field_separator.
4 5 6 |
# File 'lib/anki/deck.rb', line 4 def field_separator @field_separator end |
Instance Method Details
#generate_deck(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/anki/deck.rb', line 12 def generate_deck( = {}) raise ArgumentError, "card_headers must be an array" if !self.card_headers.is_a?(Array) raise ArgumentError, "card_headers must not be empty" if self.card_headers.empty? raise ArgumentError, "card_data must be an array" if !self.card_data.is_a?(Array) raise ArgumentError, "card_data must not be empty" if self.card_data.empty? anki_string = "" anki_string << card_header_to_string() anki_string << self.card_data.map { |card| card_data_to_string(card) }.compact.join("\n") create_file(anki_string, [:file]) if [:file] anki_string end |