Class: Embulk::GuessNewline

Inherits:
TextGuessPlugin show all
Defined in:
lib/embulk/guess_newline.rb

Instance Method Summary collapse

Methods inherited from TextGuessPlugin

#guess

Methods inherited from GuessPlugin

from_java_object, #guess, java_object

Instance Method Details

#guess_text(config, sample_text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/embulk/guess_newline.rb', line 6

def guess_text(config, sample_text)
  cr_count = sample_text.count("\r")
  lf_count = sample_text.count("\n")
  crlf_count = sample_text.scan(/\r\n/).length
  if crlf_count > cr_count / 2 && crlf_count > lf_count / 2
    return {"parser" => {"newline" => "CRLF"}}
  elsif cr_count > lf_count / 2
    return {"parser" => {"newline" => "CR"}}
  else
    return {"parser" => {"newline" => "LF"}}
  end
end