lib/masticate/sniffer.rb in masticate-0.3 vs lib/masticate/sniffer.rb in masticate-0.3.1
- old
+ new
@@ -23,11 +23,12 @@
end
def find_col_sep
@delimstats = {}
with_input do |input|
- input.lines.take(10).each do |line|
+ lines = 10.times.map{get}.compact
+ lines.each do |line|
@line1 = line unless @line1
CandidateDelimiters.each do |delim|
delimstats[delim] ||= { :counts => Set.new, :quote_char => nil}
h = delimstats[delim]
@@ -65,10 +66,14 @@
line.count(delim) + 1
end
end
def stats
+ counts = Hash.new(0)
with_input do |input|
- input.lines.each_with_object(Hash.new(0)) {|line, counts| counts[CSV.parse_line(line, :col_sep => col_sep, :quote_char => quote_char || "\0").count] += 1}
+ while line = get
+ counts[CSV.parse_line(line, :col_sep => col_sep, :quote_char => quote_char || "\0").count] += 1
+ end
end
+ counts
end
end