Class: Pipio::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/pipio/file_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_file, cleaner) ⇒ FileReader

Returns a new instance of FileReader.



3
4
5
6
7
8
# File 'lib/pipio/file_reader.rb', line 3

def initialize(path_to_file, cleaner)
  @path_to_file = path_to_file
  @first_line = ''
  @other_lines = []
  @cleaner = cleaner
end

Instance Attribute Details

#first_lineObject (readonly)

Returns the value of attribute first_line.



10
11
12
# File 'lib/pipio/file_reader.rb', line 10

def first_line
  @first_line
end

#other_linesObject (readonly)

Returns the value of attribute other_lines.



10
11
12
# File 'lib/pipio/file_reader.rb', line 10

def other_lines
  @other_lines
end

Instance Method Details

#readObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/pipio/file_reader.rb', line 12

def read
  if File.exist?(@path_to_file)
    open(@path_to_file) do |file|
      @first_line = file.readline.strip
      @other_lines = file.readlines.map(&:strip)
    end

    clean_other_lines
  end
end