Class: Bridge::Contract
- Inherits:
-
Object
- Object
- Bridge::Contract
- Defined in:
- lib/bridge/contract.rb
Instance Attribute Summary collapse
-
#bid ⇒ Object
Returns the value of attribute bid.
-
#declarer ⇒ Object
Returns the value of attribute declarer.
-
#double_by ⇒ Object
Returns the value of attribute double_by.
-
#redouble_by ⇒ Object
Returns the value of attribute redouble_by.
Instance Method Summary collapse
-
#initialize(auction) ⇒ Contract
constructor
A new instance of Contract.
- #to_hash ⇒ Object
Constructor Details
#initialize(auction) ⇒ Contract
Returns a new instance of Contract.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bridge/contract.rb', line 8 def initialize auction raise InvalidAuctionError unless auction.complete? and !auction.passed_out? # The contract is the last (and highest) bid. self.bid = auction.current_bid # The declarer is the first partner to bid the contract denomination. caller = auction.who_called?(self.bid) partnership = [caller, Direction[(caller + 2) % 4]] # Determine which partner is declarer. auction.calls.each do |call| if call.is_a?(Bid) and call.strain == self.bid.strain bidder = auction.who_called?(call) if partnership.include?(bidder) self.declarer = bidder break end end end self.double_by, self.redouble_by = [nil, nil] if auction.current_double # The opponent who doubled the contract bid. self.double_by = auction.who_called?(auction.current_double) if auction.current_redouble # The partner who redoubled an opponent's double. self.redouble_by = auction.who_called?(auction.current_redouble) end end end |
Instance Attribute Details
#bid ⇒ Object
Returns the value of attribute bid.
4 5 6 |
# File 'lib/bridge/contract.rb', line 4 def bid @bid end |
#declarer ⇒ Object
Returns the value of attribute declarer.
4 5 6 |
# File 'lib/bridge/contract.rb', line 4 def declarer @declarer end |
#double_by ⇒ Object
Returns the value of attribute double_by.
4 5 6 |
# File 'lib/bridge/contract.rb', line 4 def double_by @double_by end |
#redouble_by ⇒ Object
Returns the value of attribute redouble_by.
4 5 6 |
# File 'lib/bridge/contract.rb', line 4 def redouble_by @redouble_by end |
Instance Method Details
#to_hash ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/bridge/contract.rb', line 39 def to_hash { :bid => bid, :declarer => declarer, :double_by => double_by, :redouble_by => redouble_by } end |