Class: Bridge::Bid
Instance Attribute Summary collapse
-
#bid ⇒ Object
readonly
Returns the value of attribute bid.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #coerce(other) ⇒ Object
- #contract? ⇒ Boolean
- #double? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #grand_slam? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(bid) ⇒ Bid
constructor
Creates a new bid.
- #inspect ⇒ Object
-
#level ⇒ Object
Returns the level of the bid.
- #major? ⇒ Boolean
- #minor? ⇒ Boolean
- #modifier? ⇒ Boolean
- #no_trump? ⇒ Boolean (also: #nt?)
- #pass? ⇒ Boolean
- #redouble? ⇒ Boolean
- #small_slam? ⇒ Boolean
-
#suit ⇒ Object
Returns the suit of the bid.
- #to_s ⇒ Object
- #trump ⇒ Object
Constructor Details
Instance Attribute Details
#bid ⇒ Object (readonly)
Returns the value of attribute bid.
5 6 7 |
# File 'lib/bridge/bid.rb', line 5 def bid @bid end |
Instance Method Details
#<=>(other) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bridge/bid.rb', line 68 def <=>(other) case other when Bid if contract? raise ArgumentError, "could not compare contract bid with non-contract bid #{other}" unless other.contract? Bridge.compare_contracts(self.bid, other.bid) elsif pass? raise ArgumentError, "could not compare pass bid with non-pass bid #{other}" unless other.pass? bid <=> other.bid elsif double? raise ArgumentError, "could not compare double bid with non-double bid #{other}" unless other.double? bid <=> other.bid elsif redouble? raise ArgumentError, "could not compare redouble bid with non-redouble bid #{other}" unless other.redouble? bid <=> other.bid end when String self <=> Bid.new(other) else begin a, b = other.coerce(self) a <=> b rescue end end end |
#coerce(other) ⇒ Object
95 96 97 |
# File 'lib/bridge/bid.rb', line 95 def coerce(other) [Bid.new(other.to_s), self] end |
#contract? ⇒ Boolean
64 65 66 |
# File 'lib/bridge/bid.rb', line 64 def contract? Bridge.contract?(bid) end |
#eql?(other) ⇒ Boolean
99 100 101 |
# File 'lib/bridge/bid.rb', line 99 def eql?(other) self == other && other.instance_of?(Bid) end |
#grand_slam? ⇒ Boolean
60 61 62 |
# File 'lib/bridge/bid.rb', line 60 def grand_slam? level.to_i == 7 end |
#hash ⇒ Object
103 104 105 |
# File 'lib/bridge/bid.rb', line 103 def hash bid.hash end |
#inspect ⇒ Object
111 112 113 |
# File 'lib/bridge/bid.rb', line 111 def inspect bid.inspect end |
#level ⇒ Object
Returns the level of the bid
14 15 16 |
# File 'lib/bridge/bid.rb', line 14 def level bid[0] if contract? end |
#modifier? ⇒ Boolean
52 53 54 |
# File 'lib/bridge/bid.rb', line 52 def modifier? Bridge.modifier?(bid) end |
#no_trump? ⇒ Boolean Also known as: nt?
35 36 37 |
# File 'lib/bridge/bid.rb', line 35 def no_trump? Bridge.no_trump?(suit) end |
#redouble? ⇒ Boolean
48 49 50 |
# File 'lib/bridge/bid.rb', line 48 def redouble? Bridge.redouble?(bid) end |
#small_slam? ⇒ Boolean
56 57 58 |
# File 'lib/bridge/bid.rb', line 56 def small_slam? level.to_i == 6 end |
#suit ⇒ Object
Returns the suit of the bid
19 20 21 |
# File 'lib/bridge/bid.rb', line 19 def suit bid[1..-1] if contract? end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/bridge/bid.rb', line 107 def to_s bid end |