Class: RubyQuiz2::SelectionParty
- Inherits:
-
Object
- Object
- RubyQuiz2::SelectionParty
- Defined in:
- lib/ruby_quiz_2/selection_party.rb
Instance Attribute Summary collapse
-
#attendees ⇒ Object
readonly
Returns the value of attribute attendees.
-
#people_list ⇒ Object
readonly
Returns the value of attribute people_list.
Instance Method Summary collapse
-
#initialize(people_list) ⇒ SelectionParty
constructor
A new instance of SelectionParty.
- #make_selections ⇒ Object
- #selection_rules ⇒ Object
- #selections ⇒ Object
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
#attendees ⇒ Object (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_list ⇒ Object (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_selections ⇒ Object
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_rules ⇒ Object
14 15 16 |
# File 'lib/ruby_quiz_2/selection_party.rb', line 14 def selection_rules @selection_rules ||= SelectionRules.new end |
#selections ⇒ Object
10 11 12 |
# File 'lib/ruby_quiz_2/selection_party.rb', line 10 def selections @selections ||= [] end |