lib/bmg/reader/csv.rb in bmg-0.5.0 vs lib/bmg/reader/csv.rb in bmg-0.6.0
- old
+ new
@@ -6,11 +6,12 @@
DEFAULT_OPTIONS = {
:headers => true,
:return_headers => false
}
- def initialize(path, options = {})
+ def initialize(type, path, options = {})
+ @type = type
@path = path
@options = DEFAULT_OPTIONS.merge(options)
@options[:col_sep] ||= infer_col_sep
@options[:quote_char] ||= infer_quote_char
end
@@ -19,9 +20,18 @@
require 'csv'
::CSV.foreach(@path, @options) do |row|
yield tuple(row)
end
end
+
+ def to_ast
+ [ :csv, @path, @options ]
+ end
+
+ def to_s
+ "(csv #{path})"
+ end
+ alias :inspect :to_s
private
def tuple(row)
row.to_hash.each_with_object({}){|(k,v),h| h[k.to_sym] = v }