Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/recommendify/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ def self.max_neighbors(n=nil)
end

def self.input_matrix(key, opts)
@@input_matrices[key] = opts
@@input_matrices[self.to_s] = {} if @@input_matrices[self.to_s].nil?
@@input_matrices[self.to_s][key] = opts
end

def self.input_matrices
@@input_matrices
end

def initialize
@input_matrices = Hash[self.class.input_matrices.map{ |key, opts|
@@input_matrices[self.class.to_s] = {} if @@input_matrices[self.class.to_s].nil?
@input_matrices = Hash[self.class.input_matrices[self.class.to_s].map{ |key, opts|
opts.merge!(:key => key, :redis_prefix => redis_prefix)
[ key, Recommendify::InputMatrix.create(opts) ]
}]
Expand Down Expand Up @@ -83,4 +85,4 @@ def delete_item!(item_id)
end
end

end
end
3 changes: 2 additions & 1 deletion spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

it "should add an input_matrix by 'key'" do
Recommendify::Base.input_matrix(:myinput, :similarity_func => :jaccard)
Recommendify::Base.send(:class_variable_get, :@@input_matrices).keys.should == [:myinput]
Recommendify::Base.send(:class_variable_get, :@@input_matrices).keys.should == [ "Recommendify::Base" ]
Recommendify::Base.send(:class_variable_get, :@@input_matrices)["Recommendify::Base"].keys.should == [:myinput]
end

it "should retrieve an input_matrix on a new instance" do
Expand Down