Sha256: e806469ce8ecc57d1020ea285cb2a1d40fd5afa3c035423e4e8a95bb0184d2c1
Contents?: true
Size: 1022 Bytes
Versions: 4
Compression:
Stored size: 1022 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.reduce(nil) do |acc, provider_name| camelized = ActiveSupport::Inflector.camelize("crawler/operator/providers/#{provider_name.to_s}") klass = ActiveSupport::Inflector.constantize(camelized) result = klass.resolve(name, full_address) break result if result end return operator if operator return unless default_provider default_provider.resolve(name, full_address) end end end
Version data entries
4 entries across 4 versions & 1 rubygems