Total Complexity | 5 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # frozen_string_literal: true |
||
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 |