Sha256: b85f548e39ca7a8b2947a2ef59736b74793adf733b594fd557beb0b05acec80e

Contents?: true

Size: 924 Bytes

Versions: 10

Compression:

Stored size: 924 Bytes

Contents

module Chronicle
  module ETL
    class JSONExtractor < Chronicle::ETL::Extractor
      include Extractors::Helpers::InputReader

      register_connector do |r|
        r.description = 'JSON'
      end

      setting :jsonl, default: true, type: :boolean

      def prepare
        @jsons = []
        load_input do |input|
          @jsons << parse_data(input)
        end
      end

      def extract
        @jsons.each do |json|
          yield Chronicle::ETL::Extraction.new(data: json)
        end
      end

      def results_count
        @jsons.count
      end

      private

      def parse_data data
        JSON.parse(data)
      rescue JSON::ParserError
        raise Chronicle::ETL::ExtractionError, "Could not parse JSON"
      end

      def load_input(&block)
        if @config.jsonl
          read_input_as_lines(&block)
        else
          read_input(&block)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
chronicle-etl-0.5.5 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.5.4 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.5.3 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.5.2 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.5.1 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.5.0 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.4.4 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.4.3 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.4.2 lib/chronicle/etl/extractors/json_extractor.rb
chronicle-etl-0.4.1 lib/chronicle/etl/extractors/json_extractor.rb