Sha256: 0e6e6f11907711c145513dc68f130012bf92c8fe85187ff2b5c50de0316699eb

Contents?: true

Size: 1.62 KB

Versions: 14

Compression:

Stored size: 1.62 KB

Contents

class Card
  class Migration
    class Import
      class ImportData
       # handles card attributes for import
       module CardAttributes
         def card_attributes data
           card_attr = ::Set.new [:name, :type, :codename, :file, :image]
           data.select { |k, v| v && card_attr.include?(k) }
         end

         def update_card_attributes card_data
           card_entry = find_card_attributes card_data[:name]
           # we only want strings and not the whole name objects
           # for name and type
           card_data[:name] = card_data[:name].to_s
           card_data[:type] = card_data[:type].to_s
           if card_entry
             card_entry.replace card_data
           else
             cards << card_data
           end
         end

         def update_attribute name, attr_key, attr_value
           card = find_card_attributes name
           return unless card
           card[attr_key] = attr_value
           card
         end

         def write_attributes
           File.write @path, @data.to_yaml
         end

         def read_attributes
           ensure_path
           return { cards: [], remotes: {} } unless File.exist? @path
           YAML.load_file(@path).deep_symbolize_keys
         end

         def find_card_attributes name
           key = name.to_name.key
           cards.find do |attr|
             key == (attr[:key].present? ? attr[:key] : attr[:name].to_name.key)
           end
         end

         private

         def ensure_path
           dir = File.dirname(@path)
           FileUtils.mkpath dir unless Dir.exist? dir
         end
       end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
card-1.94.0 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.13 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.12 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.11 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.10 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.9 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.8 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.7 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.6 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.5 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.4 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.3 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.2 lib/card/migration/import/import_data/card_attributes.rb
card-1.93.1 lib/card/migration/import/import_data/card_attributes.rb