Class: StableMatching::Marriage::PreferenceTable

Inherits:
PreferenceTable
  • Object
show all
Defined in:
lib/stable-matching/marriage/preference_table.rb

Instance Attribute Summary collapse

Attributes inherited from PreferenceTable

#name_to_member_mapping

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PreferenceTable

#complete?, #members, #print, #to_s

Constructor Details

#initialize(raw_preference_table) ⇒ PreferenceTable

Returns a new instance of PreferenceTable.



23
24
25
26
27
28
29
30
31
32
# File 'lib/stable-matching/marriage/preference_table.rb', line 23

def initialize(raw_preference_table)
  members = initialize_members_from(raw_preference_table)

  @raw_preference_table = raw_preference_table

  # Avoid calling the parent initializer, but we still need to set
  # the delegated object. Thankfully SimpleDelegator offers a method
  # to set this directly
  __setobj__(members)
end

Instance Attribute Details

#partner_tableObject

Returns the value of attribute partner_table.



11
12
13
# File 'lib/stable-matching/marriage/preference_table.rb', line 11

def partner_table
  @partner_table
end

Class Method Details

.initialize_pair(raw_preference_table_a, raw_preference_table_b) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/stable-matching/marriage/preference_table.rb', line 13

def self.initialize_pair(raw_preference_table_a, raw_preference_table_b)
  table_a = new(raw_preference_table_a)
  table_b = new(raw_preference_table_b)

  table_a.partner_table = table_b
  table_b.partner_table = table_a

  [table_a, table_b]
end

Instance Method Details

#unmatchedObject



46
47
48
49
50
51
# File 'lib/stable-matching/marriage/preference_table.rb', line 46

def unmatched
  have_accepted = partner_table.members.select(&:accepted_proposal?)
  have_been_accepted = have_accepted.map(&:current_proposer)

  members - have_been_accepted
end