Sha256: 2dc962ecd537913741a55f4ebf94bec6a7ba2372716273ea721d9f620d081e7f

Contents?: true

Size: 598 Bytes

Versions: 2

Compression:

Stored size: 598 Bytes

Contents

# frozen_string_literal: true

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

module StreamLines
  module Reading
    class JSONLines
      include Enumerable

      def initialize(url, encoding: Encoding.default_external, **json_options)
        @url = url
        @json_options = json_options
        @stream = Stream.new(url, encoding: encoding)
      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.4.1 lib/stream_lines/reading/json_lines.rb
stream_lines-0.4.0 lib/stream_lines/reading/json_lines.rb