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

CsvSource   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A each() 0 5 1
A initialize() 0 4 1
A to_s() 0 4 2
A read() 0 3 1
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