Class: RubyQuiz2::SelectionParty

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_quiz_2/selection_party.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(people_list) ⇒ SelectionParty

Returns a new instance of SelectionParty.



6
7
8
# File 'lib/ruby_quiz_2/selection_party.rb', line 6

def initialize(people_list)
  @people_list = people_list
end

Instance Attribute Details

#attendeesObject (readonly)

Returns the value of attribute attendees.



4
5
6
# File 'lib/ruby_quiz_2/selection_party.rb', line 4

def attendees
  @attendees
end

#people_listObject (readonly)

Returns the value of attribute people_list.



4
5
6
# File 'lib/ruby_quiz_2/selection_party.rb', line 4

def people_list
  @people_list
end

Instance Method Details

#make_selectionsObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_quiz_2/selection_party.rb', line 18

def make_selections
  while selections.empty? && possible_selections.any?
    candidate_selections = possible_selections.shift
    if selection_rules.valid_set?(candidate_selections)
      self.selections.replace(candidate_selections)
    end
  end
  unless selections.any?
    raise ArgumentError, "there are no valid combinations of selections"
  end
end

#selection_rulesObject



14
15
16
# File 'lib/ruby_quiz_2/selection_party.rb', line 14

def selection_rules
  @selection_rules ||= SelectionRules.new
end

#selectionsObject



10
11
12
# File 'lib/ruby_quiz_2/selection_party.rb', line 10

def selections
  @selections ||= []
end