module Predictable::Item

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

Public Instance Methods

add_to_recommender(attrs={}) click to toggle source

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

# File lib/predictable/item.rb, line 37
def add_to_recommender(attrs={})
  recommender.create_item(self, attrs)
  nil
end
delete_from_recommender() click to toggle source

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

# File lib/predictable/item.rb, line 44
def delete_from_recommender
  recommender.delete_item(self)
  nil
end
pio_iid() click to toggle source

Returns the item id

# File lib/predictable/item.rb, line 25
def pio_iid
  "#{self.class.pio_itype}-#{id}"
end
pio_itypes() click to toggle source

Returns the item types

# File lib/predictable/item.rb, line 30
def pio_itypes
  [self.class.pio_itype]
end

Protected Instance Methods

recommender() click to toggle source
# File lib/predictable/item.rb, line 51
def recommender
  self.class.recommender
end