Skip to content

Instantly share code, notes, and snippets.

@halan
Forked from cesarmedeiros/gist:4171441
Created November 29, 2012 20:01
Show Gist options
  • Save halan/4171492 to your computer and use it in GitHub Desktop.
Save halan/4171492 to your computer and use it in GitHub Desktop.
Sugestão de leituras com base no Tracking de leituras anteriores
require 'rubygems'
require 'redis'
class Datanosql
def initialize
@r = Redis.new
end
def get_noticias_lida_por(user_id)
@r.smembers(user_id)
end
def get_leitores_que_leram(not_id)
@r.smembers(not_id)
end
end
class Noticia
def initialize
@d = Datanosql.new
end
def get_readers(not_id)
@d.get_leitores_que_leram(not_id)
end
end
class Leitor
def initialize
@d = Datanosql.new
end
def noticias_lidas(user_id)
@d.get_noticias_lida_por(user_id)
end
end
class Sugestao
def get(usuario, noticia)
@l = Leitor.new
@n = Noticia.new
@n.get_readers(noticia).map { |user_id| @l.noticias_lidas('user_' + user_id ) }
sugestao = noticias - @l.noticias_lidas(usuario)
sugestao.uniq!.sort
end
end
s = Sugestao.new
puts 'leituras sugeridas...'
puts s.get('user_13', 'not_16')
puts 'lido....'
l = Leitor.new
puts l.noticias_lidas('user_13')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment