Completed
Push — master ( 683061...c652b8 )
by Steven
04:24
created

CsvSource.read()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
# frozen_string_literal: true
2
3
require 'csv'
4
5
# Helper class to process CSV files
6
class CsvSource
7
  def initialize(file, options)
8
    @file = file
9
    @options = options
10
  end
11
  
12
  def each
13
    CSV.foreach(@file, @options) do |row|
14
      yield row.to_hash
15
    end
16
  end
17
18
  # returns an array of arrays containing file contents
19
  def read
20
    @arrays = CSV.read(@file)
21
  end
22
23
  # returns a line delimited single string
24
  def to_s
25
    read unless @arrays
26
    @arrays.map(&:join).join("\n")
27
  end
28
end
29