Module: Crawler::Operator
- Includes:
- Base, Configuration
- Defined in:
- lib/crawler/operator.rb,
lib/crawler/operator/core/version.rb,
lib/crawler/operator/configuration.rb
Defined Under Namespace
Modules: Core
Classes: Configuration
Constant Summary
collapse
- PROVIDERS =
[]
Class Method Summary
collapse
Class Method Details
.add_provider(provider_name, options = {}) ⇒ Object
12
13
14
15
16
|
# File 'lib/crawler/operator.rb', line 12
def self.add_provider(provider_name, options = {})
options.assert_valid_keys :insert_at
PROVIDERS.insert(options[:insert_at] || -1, provider_name)
end
|
.resolve(name, address) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/crawler/operator.rb', line 18
def self.resolve(name, address)
full_address = 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 config.default_provider
config.default_provider.resolve(name, full_address)
end
|