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.



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

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.



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

def level
  @level
end

#strainObject

Returns the value of attribute strain.



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

def strain
  @strain
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



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

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