Sha256: 0e3db8d84f00028d98e7431ffdeb7837101a3f74a5cda39190e980386b31f682

Contents?: true

Size: 831 Bytes

Versions: 28

Compression:

Stored size: 831 Bytes

Contents

module Workarea
  class Segment
    module Rules
      class Geolocation < Base
        field :locations, type: Array, default: []

        def qualifies?(visit)
          return false if locations.blank?

          visit_locations = matchable_locations_for(visit)
          return false if visit_locations.blank?

          matchable_locations = locations.map(&:downcase)
          visit_locations.any? { |l| l.in?(matchable_locations) }
        end

        def matchable_locations_for(visit)
          option_ids = [
            visit.postal_code,
            GeolocationOption.from_subdivision(visit.country, visit.subdivision)&.id,
            GeolocationOption.from_country(visit.country)&.id
          ]

          (visit.location_names + option_ids).reject(&:blank?).map(&:downcase)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.26 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.25 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.23 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.22 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.21 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.20 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.19 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.18 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.17 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.16 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.15 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.14 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.13 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.12 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.11 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.10 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.9 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.8 app/models/workarea/segment/rules/geolocation.rb
workarea-core-3.5.7 app/models/workarea/segment/rules/geolocation.rb