Sha256: 49c0a6d8fd951e9511d80d4ce7cf638481622ea46d16f3c176b4fe30c121961e

Contents?: true

Size: 541 Bytes

Versions: 2

Compression:

Stored size: 541 Bytes

Contents

# frozen_string_literal: true

require 'json'
require 'stream_lines/reading/stream'

module StreamLines
  module Reading
    class JSONLines
      include Enumerable

      def initialize(url, **json_options)
        @url = url
        @json_options = json_options
        @stream = Stream.new(url)
      end

      def each(&block)
        @stream.each { |line| block.call(parse_line(line)) }
      end

      private

      attr_reader :url

      def parse_line(line)
        JSON.parse(line, **@json_options)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stream_lines-0.3.1 lib/stream_lines/reading/json_lines.rb
stream_lines-0.3.0 lib/stream_lines/reading/json_lines.rb