Class: Proposer

Inherits:
Object
  • Object
show all
Defined in:
lib/gale_shapley/proposer.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, preferences) ⇒ Proposer

Returns a new instance of Proposer.



6
7
8
9
10
11
# File 'lib/gale_shapley/proposer.rb', line 6

def initialize(name, preferences)
  @name = name
  @preferences = preferences
  @index = 0
  @engaged = false
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/gale_shapley/proposer.rb', line 4

def name
  @name
end

Instance Method Details

#current_acceptor_nameObject



21
22
23
# File 'lib/gale_shapley/proposer.rb', line 21

def current_acceptor_name
  @preferences[@index]
end

#engageObject



17
18
19
# File 'lib/gale_shapley/proposer.rb', line 17

def engage
  @engaged = true
end

#freeObject



33
34
35
36
# File 'lib/gale_shapley/proposer.rb', line 33

def free
  @index += 1
  @engaged = false
end

#propose(acceptor) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/gale_shapley/proposer.rb', line 25

def propose(acceptor)
  if acceptor.engaged?
    acceptor.more_attractive?(self) ? acceptor.engage(self) : free
  else
    acceptor.engage(self)
  end
end

#unengaged?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/gale_shapley/proposer.rb', line 13

def unengaged?
  !@engaged
end