Sha256: a668917320b30e6957a4a66c50bd5ae85c90b653bf9978c5bdf95eca137e1d38
Contents?: true
Size: 1.47 KB
Versions: 10
Compression:
Stored size: 1.47 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] 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 index = cards.find_index { |attr| attr[:key] == key } || cards.find_index { |attr| attr[:name] == name } return unless index cards[index] 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
10 entries across 10 versions & 1 rubygems