Sha256: 715584700ef77a0b6c6ee8fb023d7d0c235fc1a3a2e2bdf63d379c89b1fb05a8
Contents?: true
Size: 774 Bytes
Versions: 3
Compression:
Stored size: 774 Bytes
Contents
require "array_hasher/version" require "array_hasher/formatter" require 'csv' require 'json' module ArrayHasher class << self def new_formatter(cols) Formatter.new(cols) end def parse_format(definition) definition.map do |val| name, type, opts = val.to_s.split(':', 3) [ (name && name.length > 0) ? name.to_sym : nil, (type && type.length > 0) ? type.to_sym : nil, (opts && opts =~ /\A\{.*\}\z/) ? JSON.parse(opts) : {} ] end end def csv_each(path, ext_types = {}, &block) csv = CSV.open(path) formatter = new_formatter(parse_format(csv.gets)) formatter.types.merge!(ext_types) csv.each { |line| block.call(formatter.parse(line)) } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
array_hasher-0.1.3 | lib/array_hasher.rb |
array_hasher-0.1.2 | lib/array_hasher.rb |
array_hasher-0.1.1 | lib/array_hasher.rb |