Class: Detector::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/detector/region.rb

Class Method Summary collapse

Class Method Details

.detect_region(host, geo) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/detector/region.rb', line 4

def detect_region(host, geo)
  return nil unless host || geo
  
  hostname = host.to_s.downcase
  
  # Try to determine region from hostname first
  aws_region = detect_aws_region(hostname)
  return aws_region if aws_region
  
  azure_region = detect_azure_region(hostname)
  return azure_region if azure_region
  
  gcp_region = detect_gcp_region(hostname)
  return gcp_region if gcp_region
  
  # Fallbacks to geocoder data
  return nil unless geo
  
  # Try city-based detection
  city_region = detect_region_by_city(geo&.data&.dig('city')&.downcase)
  return city_region if city_region
  
  # Try region/country based detection
  geo_region = detect_region_by_geography(geo&.data&.dig('region'), geo&.data&.dig('country'))
  return geo_region if geo_region
  
  # Final fallback
  geo&.data&.dig('region') || geo&.data&.dig('country_code')&.downcase
end