Class: Dsu::Services::TempFile::ReaderService

Inherits:
Object
  • Object
show all
Defined in:
lib/dsu/services/temp_file/reader_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(tmp_file_path:, options: {}) ⇒ ReaderService

Returns a new instance of ReaderService.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dsu/services/temp_file/reader_service.rb', line 7

def initialize(tmp_file_path:, options: {})
  raise ArgumentError, 'tmp_file_path is nil' if tmp_file_path.nil?
  raise ArgumentError, 'tmp_file_path is the wrong object type' unless tmp_file_path.is_a?(String)
  raise ArgumentError, 'tmp_file_path is empty' if tmp_file_path.empty?
  raise ArgumentError, 'tmp_file_path does not exist' unless File.exist?(tmp_file_path)
  raise ArgumentError, 'options is nil' if options.nil?
  raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

  @tmp_file_path = tmp_file_path
  @options = options || {}
end

Instance Method Details

#callObject

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/dsu/services/temp_file/reader_service.rb', line 19

def call
  raise ArgumentError, 'no block given' unless block_given?

  File.foreach(tmp_file_path) do |line|
    yield line.strip
  end
end