Sha256: 22a0097f88883627d1917d0d740c2284fdd1326c841a0cafc26a51e8796450ad
Contents?: true
Size: 1.24 KB
Versions: 62
Compression:
Stored size: 1.24 KB
Contents
module Workarea class Shipping class LocationQuery attr_reader :services, :country, :region def initialize(services, country, region) @services = services @country = typecast_country(country) @region = region end def location_services location_services = matching_services if has_service_with_region? location_services.select! do |service| service.regions.include?(region) end end location_services end private def matching_services @matching_services ||= services.select do |service| (country.blank? || service.country.blank? || service.country == country) && (region.blank? || service.regions.blank? || service.regions.include?(region)) end end def has_service_with_region? region.present? && matching_services.detect { |service| service.regions.include?(region) } end def typecast_country(country) if country.is_a?(::Country) country elsif country.is_a?(String) Country[country] elsif country.is_a?(ActiveUtils::Country) Country[country.code(:alpha2)] end end end end end
Version data entries
62 entries across 62 versions & 1 rubygems
Version | Path |
---|---|
workarea-core-3.4.13 | app/models/workarea/shipping/location_query.rb |
workarea-core-3.4.12 | app/models/workarea/shipping/location_query.rb |