Module: Mendel::Combiner

Includes:
Enumerable
Included in:
ObservableCombiner
Defined in:
lib/mendel/combiner.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#listsObject

Returns the value of attribute lists.



11
12
13
# File 'lib/mendel/combiner.rb', line 11

def lists
  @lists
end

#priority_queueObject

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

#dumpObject



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_jsonObject



37
38
39
# File 'lib/mendel/combiner.rb', line 37

def dump_json
  JSON.dump(dump)
end

#eachObject



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

Raises:

  • (EmptyList)


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_lengthObject



41
42
43
# File 'lib/mendel/combiner.rb', line 41

def queue_length
  priority_queue.length
end

#score_combination(items) ⇒ Object

Raises:

  • (NotImplementedError)


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"