Class: Gemstat::Population
- Inherits:
-
Object
- Object
- Gemstat::Population
- Defined in:
- lib/gemstat/population.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
- #compute_similarity_score(sample, reversed = false) ⇒ Object
-
#initialize(folder_path) ⇒ Population
constructor
A new instance of Population.
Constructor Details
#initialize(folder_path) ⇒ Population
Returns a new instance of Population.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gemstat/population.rb', line 4 def initialize(folder_path) cache_path = File.dirname(__FILE__) + '/cache/' + `du -s #{File.dirname(__FILE__)}/cache/gemfiles | cut -f1`.chomp + '.cache' if File.exist?(cache_path) then @dependencies = Marshal.load(File.read(cache_path)) else @dependencies = [] `find #{folder_path} -type d`.each_line do |line| dependency = Dependency.new(line.chomp) @dependencies.push dependency if dependency.exist? end File.open(cache_path, 'w') {|f| f.write(Marshal.dump(@dependencies)) } end end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
3 4 5 |
# File 'lib/gemstat/population.rb', line 3 def dependencies @dependencies end |
Instance Method Details
#compute_similarity_score(sample, reversed = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gemstat/population.rb', line 18 def compute_similarity_score(sample, reversed = false) result = {} @dependencies.each do |item| score = 1.0 / (1.0+((sample.gems + item.gems) - (sample.gems & item.gems)).uniq.count) if score > 1.0/(1.0+sample.gems.count) then result[item.gem_name] = {:score => score, :gems => item.gems} end end reversed ? result = result.sort{|a,b| a[1][:score] <=> b[1][:score]} : result = result.sort{|a,b| b[1][:score] <=> a[1][:score]} end |