lib/eco/csv.rb in eco-helpers-2.4.9 vs lib/eco/csv.rb in eco-helpers-2.5.1
- old
+ new
@@ -1,25 +1,22 @@
require 'csv'
-
module Eco
class CSV < ::CSV
-
class << self
+ include Eco::Data::Files
# @return [Eco::CSV::Table]
def parse(data, **kargs, &block)
kargs = {headers: true, skip_blanks: true}.merge(kargs)
Eco::CSV::Table.new(super(data, **kargs, &block))
end
# @return [Eco::CSV::Table]
def read(file, **kargs)
- kargs = {headers: true, skip_blanks: true}.merge(kargs)
- args = [file].tap do |arg|
- encoding = Eco::API::Common::Session::FileManager.encoding(file)
- arg.push("rb:bom|utf-8") if encoding == "bom"
+ params = {}.tap do |prms|
+ prms.merge!(encoding: kargs.delete(:encoding)) if kargs.key?(:encoding)
end
- Eco::CSV::Table.new(super(*args, **kargs))
+ parse(get_file_content(file, **params), **kargs)
end
end
end
end