Add a yaml DSL method.
I find the yaml format easier to read than csv (when working entirely in text, at least). This loader works on this array-formatted yaml, but not (for whatever reason, possibly library brokenness) on multi-doc format: ``` - title: Foo rank: 2 - title: Bar rank: 3 ```dev
parent
824a28c87d
commit
563f800ba7
|
|
@ -1,5 +1,6 @@
|
|||
require 'roo'
|
||||
require 'csv'
|
||||
require 'yaml'
|
||||
require_relative '../args/input_file'
|
||||
require_relative '../args/import'
|
||||
require_relative '../args/csv_opts'
|
||||
|
|
@ -67,6 +68,22 @@ module Squib
|
|||
end
|
||||
module_function :csv
|
||||
|
||||
# DSL method. See http://squib.readthedocs.io
|
||||
def yaml(opts = {})
|
||||
input = Args::InputFile.new(file: 'deck.yml').load!(opts)
|
||||
import = Args::Import.new.load!(opts)
|
||||
s = YAML.load_file(input.file[0])
|
||||
data = Squib::DataFrame.new
|
||||
# Get a universal list of keys to ensure everything is covered.
|
||||
keys = s.map {|c| c.keys}.flatten.uniq
|
||||
# Initialize the data frame; why is [] not the default value?
|
||||
keys.each {|k| data[k] = [] }
|
||||
# Load all cards into the frame, nil value if key isn't set.
|
||||
s.each {|card| keys.each {|k| data[k] << card[k] } }
|
||||
explode_quantities(data, import.explode)
|
||||
end
|
||||
module_function :yaml
|
||||
|
||||
# Check if the given CSV table has duplicate columns, and throw a warning
|
||||
# @api private
|
||||
def check_duplicate_csv_headers(table)
|
||||
|
|
|
|||
Loading…
Reference in New Issue