Class: Bridge::Bid

Inherits:
Call
  • Object
show all
Includes:
Comparable
Defined in:
lib/bridge/call.rb

Overview

A Bid represents a statement of a level and a strain.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Call

all, from_string

Constructor Details

#initialize(level, strain) ⇒ Bid

Returns a new instance of Bid.



69
70
71
72
# File 'lib/bridge/call.rb', line 69

def initialize(level, strain)
  self.level  = level.is_a?(Integer)  ? level : Level.send(level.to_sym)
  self.strain = strain.is_a?(Integer) ? strain : Strain.send(strain.to_sym)
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



67
68
69
# File 'lib/bridge/call.rb', line 67

def level
  @level
end

#strainObject

Returns the value of attribute strain.



67
68
69
# File 'lib/bridge/call.rb', line 67

def strain
  @strain
end

Instance Method Details

#<=>(other) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/bridge/call.rb', line 75

def <=>(other)
  if other.is_a?(Bid) # Compare two bids.
    s_size = Strain.values.size
    # puts "#{self.level*s_size + self.strain} <=> #{other.level*s_size + other.strain}"
    (self.level*s_size + self.strain) <=> (other.level*s_size + other.strain)
  else # Comparing non-bid calls returns true.
    1
  end
end

#to_sObject



85
86
87
# File 'lib/bridge/call.rb', line 85

def to_s
  "#{Level.name(level)} #{Strain.name(strain)}"
end