-
La version Factory telle que je l'imagine
class Csv def self.build_with_header(content, col_sep: ';') new(content, col_sep: col_sep, headers: true) end def self.build_without_header(content, col_sep: ';') new(content, col_sep: col_sep, headers: false) end private # A private initializer force the usage of the class factory methods def initialize(content, col_sep:, headers:) @content = content @col_sep = col_sep @headers = headers end def book_metadata lines = CSV.new(@content, col_sep: @col_sep, headers: @headers).readlines lines.map { |line| line.to_csv(col_sep: @col_sep).strip } end end
Please register or sign in to comment