Module: Predictable::Item

Extended by:
ActiveSupport::Concern
Defined in:
lib/predictable/item.rb

Overview

Predictable Item Role

Defines the Item role for the recommender. This module should be included in any model that represents items that will be recommended.

class Offer < ActiveRecord::Base
  include Predictable::Item
  ...
end

class Article < ActiveRecord::Base
  include Predictable::Item
  ...
end

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_to_recommender(attrs = {}) ⇒ Object

Creates or updates the item in prediction.io When the item already exists, it updates it. The operation is done asynchronously.



43
44
45
46
# File 'lib/predictable/item.rb', line 43

def add_to_recommender(attrs={})
  recommender.create_item(self, attrs)
  nil
end

#delete_from_recommenderObject

Removes the item from prediction.io The operation is done asynchronously.



50
51
52
53
# File 'lib/predictable/item.rb', line 50

def delete_from_recommender
  recommender.delete_item(self)
  nil
end

#pio_iidObject

Returns the item id



31
32
33
# File 'lib/predictable/item.rb', line 31

def pio_iid
  "#{self.class.pio_itype}-#{id}"
end

#pio_itypesObject

Returns the item types



36
37
38
# File 'lib/predictable/item.rb', line 36

def pio_itypes
  [self.class.pio_itype]
end