csv: yield to block on each cell

Closes #151

Related to #145
This commit is contained in:
Andy Meneely
2016-04-11 20:07:55 -04:00
parent 39346d53c2
commit 795b4e4478
5 changed files with 71 additions and 2 deletions
+12 -1
View File
@@ -32,6 +32,7 @@ module Squib
# DSL method. See http://squib.readthedocs.org
def csv(opts = {})
# TODO refactor all this out to separate methods, and its own class
import = Args::Import.new.load!(opts)
file = Args::InputFile.new(file: 'deck.csv').load!(opts).file[0]
data = opts.key?(:data) ? opts[:data] : File.read(file)
@@ -47,10 +48,20 @@ module Squib
if import.strip?
new_hash = Hash.new
hash.each do |header, col|
new_hash[header] = col.map { |str| str = str.strip if str.respond_to?(:strip); str }
new_hash[header] = col.map do |str|
str = str.strip if str.respond_to?(:strip)
str
end
end
hash = new_hash
end
if block_given?
hash.each do |header, col|
col.map! do |val|
yield(header, val)
end
end
end
return explode_quantities(hash, import.explode)
end
module_function :csv