Class: Likes::Engines::BestIntersectionSize::Intersections

Inherits:
Object
  • Object
show all
Defined in:
lib/likes/engines/best_intersection_size.rb

Overview

Job: Understands similar tastes

Constant Summary collapse

NO_LIMIT =
Object.new.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(person, size_transform) ⇒ Intersections

Returns a new instance of Intersections.



95
96
97
98
99
100
# File 'lib/likes/engines/best_intersection_size.rb', line 95

def initialize(person, size_transform)
  @sizes = {}
  @person = person
  @best_size = NO_LIMIT
  @size_transform = size_transform
end

Class Method Details

.build(person) ⇒ Object



91
92
93
# File 'lib/likes/engines/best_intersection_size.rb', line 91

def self.build(person)
  new(person, NullSizeTransform.new)
end

Instance Method Details

#add_similar_tastes(people) ⇒ Object



102
103
104
105
106
107
# File 'lib/likes/engines/best_intersection_size.rb', line 102

def add_similar_tastes(people)
  people.each do |other_person|
    next if person == other_person
    sizes[other_person] = sizes.fetch(other_person, 0) + 1
  end
end

#next_people_with_similar_tastesObject



109
110
111
# File 'lib/likes/engines/best_intersection_size.rb', line 109

def next_people_with_similar_tastes
  candidates_with(next_best_size)
end