Sha256: 3ec10d94c91094904428f1fa6173bb50d8861001b019861772c8be6bc0e609bd

Contents?: true

Size: 957 Bytes

Versions: 28

Compression:

Stored size: 957 Bytes

Contents

module Workarea
  module Metrics
    class Affinity
      include ApplicationDocument

      field :product_ids, type: Array, default: []
      field :category_ids, type: Array, default: []
      field :search_ids, type: Array, default: []

      embedded_in :user, class_name: 'Workarea::Metrics::User'

      def recent_product_ids(max: Workarea.config.affinity_default_recent_size, unique: false)
        recent_ids(product_ids, max: max, unique: unique)
      end

      def recent_category_ids(max: Workarea.config.affinity_default_recent_size, unique: false)
        recent_ids(category_ids, max: max, unique: unique)
      end

      def recent_search_ids(max: Workarea.config.affinity_default_recent_size, unique: false)
        recent_ids(search_ids, max: max, unique: unique)
      end

      private

      def recent_ids(ids, max:, unique:)
        ids = ids.reverse
        ids.uniq! if unique
        ids.take(max)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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