class Services::Application::WeatherByAddress::Acl
ACL (Anti-Corruption Layer)
Shields the domain from external API data structures by translating raw response hashes into domain value objects. This is the classic DDD Anti-Corruption Layer pattern: the domain never sees Googleβs JSON shape β only clean value objects.
All public methods are pure mappings β no side-effects, no I/O.
Example
acl = Services::Application::WeatherByAddress::Acl.new location = acl.build_location(geocode_response) current = acl.build_current_weather(raw_hash)
Public Instance Methods
Source
# File app/services/application/weather_by_address/acl.rb 36 def build_current_weather(data) 37 time_zone_id = data.dig("timeZone", "id").to_s.presence || "UTC" 38 39 Domains::Weather::CurrentWeather.new( 40 current_time: parse_time(data["currentTime"]), 41 time_zone_id: time_zone_id, 42 is_daytime: data["isDaytime"], 43 weather_condition: build_weather_condition(data["weatherCondition"]), 44 temperature_degrees: data.dig("temperature", "degrees").to_f, 45 feels_like_degrees: data.dig("feelsLikeTemperature", "degrees")&.to_f 46 ) 47 end
@param data [Hash] raw current-weather payload from the API @return [Domains::Weather::CurrentWeather]
Source
# File app/services/application/weather_by_address/acl.rb 57 def build_daily_forecast_entries(data) 58 (data["forecastDays"] || []).map { |d| build_daily_entry(d) } 59 end
@param data [Hash] raw daily-forecast payload from the API @return [Array<Domains::Weather::DailyForecastEntry>]
Source
# File app/services/application/weather_by_address/acl.rb 51 def build_hourly_forecast_entries(data) 52 (data["forecastHours"] || []).map { |h| build_hourly_entry(h) } 53 end
@param data [Hash] raw hourly-forecast payload from the API @return [Array<Domains::Weather::HourlyForecastEntry>]
Source
# File app/services/application/weather_by_address/acl.rb 25 def build_location(geocode_response) 26 Domains::Geocode::Location.new( 27 latitude: geocode_response.latitude, 28 longitude: geocode_response.longitude, 29 zipcode: geocode_response.zipcode, 30 formatted_address: geocode_response.formatted_address 31 ) 32 end
@param geocode_response [#latitude, longitude, zipcode, formatted_address] @return [Domains::Geocode::Location]