Class: Recommendify::SparseMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/recommendify/sparse_matrix.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SparseMatrix

Returns a new instance of SparseMatrix.



3
4
5
# File 'lib/recommendify/sparse_matrix.rb', line 3

def initialize(opts={})
  @opts = opts
end

Instance Method Details

#[](x, y) ⇒ Object



11
12
13
# File 'lib/recommendify/sparse_matrix.rb', line 11

def [](x,y)
  k_get(key(x,y))
end

#[]=(x, y, v) ⇒ Object



15
16
17
# File 'lib/recommendify/sparse_matrix.rb', line 15

def []=(x,y,v)
  v == 0 ? k_del(key(x,y)) : k_set(key(x,y), v)
end

#incr(x, y) ⇒ Object



19
20
21
# File 'lib/recommendify/sparse_matrix.rb', line 19

def incr(x,y)
  k_incr(key(x,y))
end

#redis_keyObject



7
8
9
# File 'lib/recommendify/sparse_matrix.rb', line 7

def redis_key
  [@opts.fetch(:redis_prefix), @opts.fetch(:key)].join(":")
end