Class: CandidateExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/threesmodel/candidate_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(line_folder = LineFolder.new) ⇒ CandidateExtractor

Returns a new instance of CandidateExtractor.



4
5
6
# File 'lib/threesmodel/candidate_extractor.rb', line 4

def initialize(line_folder = LineFolder.new)
  @line_folder = line_folder
end

Instance Method Details

#add_candidate(candidates, index, values) ⇒ Object



40
41
42
43
44
# File 'lib/threesmodel/candidate_extractor.rb', line 40

def add_candidate(candidates, index, values)
  if (@line_folder.can_fold?(values)) then
    candidates << [index, 3]
  end
end

#fold_down_candidates(state) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/threesmodel/candidate_extractor.rb', line 32

def fold_down_candidates(state)
  candidates = []
  state.column_vectors.each_index {|i|
    add_candidate(candidates, i, state.column_vectors[i].to_a.reverse)
  }
  candidates
end

#fold_left_candidates(state) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/threesmodel/candidate_extractor.rb', line 8

def fold_left_candidates(state)
  candidates = []
  state.row_vectors.each_index {|i|
    add_candidate(candidates, i, state.row_vectors[i].to_a)
  }
  candidates
end

#fold_right_candidates(state) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/threesmodel/candidate_extractor.rb', line 16

def fold_right_candidates(state)
  candidates = []
  state.row_vectors.each_index {|i|
    add_candidate(candidates, i, state.row_vectors[i].to_a.reverse)
  }
  candidates
end

#fold_up_candidates(state) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/threesmodel/candidate_extractor.rb', line 24

def fold_up_candidates(state)
  candidates = []
  state.column_vectors.each_index {|i|
    add_candidate(candidates, i, state.column_vectors[i].to_a)
  }
  candidates
end