CsvSource.to_s()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 4
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
  attr_reader :arrays
8
  attr_reader :file
9
  
10
  def initialize(file)
11
    @file = file
12
  end
13
  
14
  # returns an array of arrays containing file contents
15
  def read
16
    raise FileNotFoundException.new I18n.t :file_not_found unless File.exist? file 
17
    @arrays = CSV.read(file)
18
  end
19
20
  # returns a line delimited single string
21
  def to_s
22
    read unless arrays
23
    arrays.map(&:join).join("\n")
24
  end
25
end
26