Class: Card::Migration::Import
- Inherits:
-
Object
- Object
- Card::Migration::Import
- Defined in:
- lib/card/migration/import.rb,
lib/card/migration/import/merger.rb,
lib/card/migration/import/import_data.rb,
lib/card/migration/import/import_data/card_content.rb,
lib/card/migration/import/import_data/card_attributes.rb
Overview
Imports card data from a local or remote deck
The cards' content for the import is stored for every card in a separate file, other attributes like name or type are stored for all cards together in a yml file.
To update a card's content you only have to change the card's content file. The merge method will recognize that the file was changed since the last merge and merge it into the cards table To update other attributes change them in the yml file and either remove the 'merged' value or touch the corresponding content file
Defined Under Namespace
Classes: ImportData, Merger
Class Method Summary collapse
-
.add_card(attr) ⇒ Object
Add a card with the given attributes to the import data.
-
.add_remote(name, url) ⇒ Object
Save an url as remote deck to make it available for the pull method.
-
.merge(opts = {}) ⇒ Object
Merge the import data into the cards table.
-
.pull(name, opts = {}) ⇒ Object
Get import data from a deck.
Class Method Details
.add_card(attr) ⇒ Object
Add a card with the given attributes to the import data
48 49 50 51 52 |
# File 'lib/card/migration/import.rb', line 48 def add_card attr ImportData.update do |data| data.add_card attr end end |
.add_remote(name, url) ⇒ Object
Save an url as remote deck to make it available for the pull method
55 56 57 58 59 |
# File 'lib/card/migration/import.rb', line 55 def add_remote name, url ImportData.update do |data| data.add_remote name, url end end |
.merge(opts = {}) ⇒ Object
Merge the import data into the cards table. Bu default it merges only the data that was changed or added since the last merge.
26 27 28 |
# File 'lib/card/migration/import.rb', line 26 def merge opts={} Merger.new(opts).merge end |
.pull(name, opts = {}) ⇒ Object
Get import data from a deck
38 39 40 41 42 43 44 45 |
# File 'lib/card/migration/import.rb', line 38 def pull name, opts={} ImportData.update do |import_data| url = opts[:remote] ? import_data.url(opts.delete(:remote)) : nil fetch_card_data(name, url, opts).each do |card_data| import_data.add_card card_data end end end |