• 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment