Module: Mendel::Combiner
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#lists ⇒ Object
Returns the value of attribute lists.
-
#priority_queue ⇒ Object
Returns the value of attribute priority_queue.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_json ⇒ Object
- #each ⇒ Object
- #initialize(*lists) ⇒ Object
- #queue_length ⇒ Object
- #score_combination(items) ⇒ Object
Instance Attribute Details
#lists ⇒ Object
Returns the value of attribute lists.
11 12 13 |
# File 'lib/mendel/combiner.rb', line 11 def lists @lists end |
#priority_queue ⇒ Object
Returns the value of attribute priority_queue.
11 12 13 |
# File 'lib/mendel/combiner.rb', line 11 def priority_queue @priority_queue end |
Class Method Details
.included(target) ⇒ Object
13 14 15 |
# File 'lib/mendel/combiner.rb', line 13 def self.included(target) target.extend(ClassMethods) end |
Instance Method Details
#dump ⇒ Object
33 34 35 |
# File 'lib/mendel/combiner.rb', line 33 def dump {INPUT => lists, SEEN => seen_set.to_a, QUEUED => priority_queue.dump } end |
#dump_json ⇒ Object
37 38 39 |
# File 'lib/mendel/combiner.rb', line 37 def dump_json JSON.dump(dump) end |
#each ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/mendel/combiner.rb', line 24 def each return self.to_enum unless block_given? loop do combo = next_combination break if combo == :none yield combo end end |
#initialize(*lists) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/mendel/combiner.rb', line 17 def initialize(*lists) raise EmptyList if lists.any?(&:empty?) self.lists = lists self.priority_queue = MinPriorityQueue.new queue_combo_at(lists.map {0} ) end |
#queue_length ⇒ Object
41 42 43 |
# File 'lib/mendel/combiner.rb', line 41 def queue_length priority_queue.length end |
#score_combination(items) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mendel/combiner.rb', line 45 def score_combination(items) raise NotImplementedError, " Including class must define. Must take a combination and produce a score.\n - If you have not defined `build_combination`, `score combination` will receive\n an array of N items (one from each list)\n - If you have defined `build_combination`, `score_combination` will receive\n whatever `build_combination` returns\n MESSAGE\nend\n" |