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
Instance 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.
-
#initialize(data_path) ⇒ Import
constructor
A new instance of Import.
-
#merge(opts = {}) ⇒ Object
Merge the import data into the cards table.
-
#pull(name, opts = {}) ⇒ Object
Get import data from a deck.
Constructor Details
#initialize(data_path) ⇒ Import
Returns a new instance of Import.
18 19 20 |
# File 'lib/card/migration/import.rb', line 18 def initialize data_path @data_path = data_path end |
Instance Method Details
#add_card(attr) ⇒ Object
Add a card with the given attributes to the import data
51 52 53 54 55 |
# File 'lib/card/migration/import.rb', line 51 def add_card attr 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
58 59 60 61 62 |
# File 'lib/card/migration/import.rb', line 58 def add_remote name, url 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.
29 30 31 |
# File 'lib/card/migration/import.rb', line 29 def merge opts={} Merger.new(@data_path, opts).merge end |
#pull(name, opts = {}) ⇒ Object
Get import data from a deck
41 42 43 44 45 46 47 48 |
# File 'lib/card/migration/import.rb', line 41 def pull name, opts={} 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 |