Sha256: ca0a4345e041de628b3108b098545b18950a12b3868dfc730eb0723b9edee6bb

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

require 'active_support/core_ext/hash/keys'
require 'active_support/inflector'
require 'crawler/base'
require 'crawler/operator/providers/default/configuration'

module Crawler
  module Operator
    include Base

    PROVIDERS = []

    def self.add_provider(provider_name, options = {})
      options.assert_valid_keys :insert_at

      PROVIDERS.insert(options[:insert_at] || -1, provider_name)
    end

    def self.resolve(name, address)
      full_address = "#{address.dig(:street)}, #{address.dig(:zipcode)} #{address.dig(:city)}, #{address.dig(:country).upcase}"

      operator = PROVIDERS.find do |provider_name|
        camelized = ActiveSupport::Inflector.camelize("crawler/operator/providers/#{provider_name.to_s}")
        klass = ActiveSupport::Inflector.constantize(camelized)

        klass.resolve(name, full_address)
      end

      return operator if operator
      return unless default_provider

      default_provider.resolve(name, full_address)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crawler-operator-core-0.2.0 lib/crawler/operator.rb