Class: Recommendify::SparseMatrix
- Inherits:
-
Object
- Object
- Recommendify::SparseMatrix
- Defined in:
- lib/recommendify/sparse_matrix.rb
Instance Method Summary collapse
- #[](x, y) ⇒ Object
- #[]=(x, y, v) ⇒ Object
- #incr(x, y) ⇒ Object
-
#initialize(opts = {}) ⇒ SparseMatrix
constructor
A new instance of SparseMatrix.
- #redis_key ⇒ Object
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_key ⇒ Object
7 8 9 |
# File 'lib/recommendify/sparse_matrix.rb', line 7 def redis_key [@opts.fetch(:redis_prefix), @opts.fetch(:key)].join(":") end |