Sha256: 5fba2437d10e62fba9373d6f65e4a8d1e7e885083361245391335182a4b44aa3

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

module Jamnagar
  module Refineries
    class ContentRefinery
      def initialize(options={})
        @items     = options[:items] || []
        @refiners  = options[:refiners] || []
        @verifiers = options[:verifiers] || []
        @storage   = options[:storage] || Storage::ItemStore.new
        @logger    = options[:logger]  || Jamnagar::Utilities::SilentLogger.new
        @runner    = options[:runner]  || Jamnagar::Utilities::Runner.new
      end

      def refine
        @items.each_with_index do |item, index|
          begin
            @runner.run do
              @storage.insert(verify(enrich(convert(item))))
            end
          rescue Jamnagar::Adapters::InsertError
            @logger.error("Insert Error: _id => #{item['_id']}")
          end
        end
      end

    private
      def enrich(item)
        @refiners.each do |refiner|
          item = refiner.refine(item)
        end
        item
      end

      def verify(item)
        @verifiers.each do |verifier|
          item = verifier.verify(item)
        end
        item
      end

      def convert(item)
        return Jamnagar::Materials::Item.new(item) if item.is_a?(Hash)
        item
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jamnagar-1.3.9.1 lib/jamnagar/refineries/content_refinery.rb