Sha256: b99489fb3d92da21de30541ee9d40c01e15862f3c5ab9d1f0732961dbb2f7401
Contents?: true
Size: 722 Bytes
Versions: 5
Compression:
Stored size: 722 Bytes
Contents
require 'arc-furnace/source' require 'arc-furnace/csv_to_hash_with_duplicate_headers' require 'csv' module ArcFurnace class CSVSource < Source include CSVToHashWithDuplicateHeaders private_attr_reader :csv attr_reader :value, :file def initialize(filename: , encoding: 'UTF-8') @file = File.open(filename, encoding: encoding) @csv = CSV.new(file, encoding: encoding, headers: true).each advance end # Is this source empty? def empty? !value end def advance @value = begin csv_to_hash_with_duplicates(csv.next) if csv rescue StopIteration file.close @csv = nil nil end end end end
Version data entries
5 entries across 5 versions & 1 rubygems