Class: Zarby::Csv

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/zarby/csv.rb

Overview

this class is used to detect the column separator in a CSV file

Constant Summary collapse

COMMON_DELIMITERS =
['","', '";"', '":"', '"|"'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(content:) ⇒ Csv

Parameters:

  • content (String)


12
13
14
# File 'lib/zarby/csv.rb', line 12

def initialize(content:)
  @content = content.to_s.each_line.first.to_s.strip
end

Instance Method Details

#callString

Returns:

  • (String)


17
18
19
20
21
22
23
24
# File 'lib/zarby/csv.rb', line 17

def call
  if valid?
    delimiters[0][0][1]
  else
    raise(Zarby::ColSeparatorZarby,
          "The content to be analyzed must have one of this list as a delimiter: ',' ';' ':' '|'")
  end
end