Sha256: c11600328f828924ee6939468350fa7af26a32cf69d3876916da39b90a81caf7
Contents?: true
Size: 850 Bytes
Versions: 3
Compression:
Stored size: 850 Bytes
Contents
require 'yaml' require_relative 'data_frame' require_relative 'quantity_exploder' module Squib::Import class YamlImporter include Squib::Import::QuantityExploder def import_to_dataframe(import, &block) data = import.data.nil? ? File.read(import.file) : import.data yml = YAML.load(data) data = Squib::DataFrame.new # Get a universal list of keys to ensure everything is covered. keys = yml.map { |c| c.keys}.flatten.uniq keys.each { |k| data[k] = [] } #init arrays yml.each do |card| # nil value if key isn't set. keys.each { |k| data[k] << card[k] } end unless block.nil? data.each do |header, col| col.map! do |val| block.yield(header, val) end end end explode_quantities(data, import.explode) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
squib-0.19.0 | lib/squib/import/yaml_importer.rb |
squib-0.19.0b | lib/squib/import/yaml_importer.rb |
squib-0.19.0a | lib/squib/import/yaml_importer.rb |