Sha256: fadf1450542b7d1a3d01c9a1d6d7c4525fa9563dc09d2d3044aacf51cb918cf5

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

require 'active_support/core_ext/hash/keys'
require 'active_support/inflector'
require 'crawler/base'
require 'crawler/operator/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.1 lib/crawler/operator.rb