Class: StreamLines::Reading::Stream

Inherits:
Object
  • Object
show all
Includes:
Enumerable, HTTParty
Defined in:
lib/stream_lines/reading/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, encoding: Encoding.default_external) ⇒ Stream

Returns a new instance of Stream.



15
16
17
18
19
# File 'lib/stream_lines/reading/stream.rb', line 15

def initialize(url, encoding: Encoding.default_external)
  @url = url
  @encoding = encoding
  @buffer = String.new(encoding: @encoding)
end

Instance Method Details

#each(&block) ⇒ Object



21
22
23
24
25
# File 'lib/stream_lines/reading/stream.rb', line 21

def each(&block)
  stream_lines(&block)
rescue HTTParty::Error => e
  raise Error, "Failed to download #{url} with code: #{e.response.code}"
end