Class: Bridge::Call

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

Overview

Abstract class, inherited by Bid, Pass, Double and Redouble.

Direct Known Subclasses

Bid, Double, Pass, Redouble

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



48
49
50
51
52
53
54
# File 'lib/bridge/call.rb', line 48

def self.all
  calls = Strain.all.map { |s| Level.all.map { |l| Bid.new(l,s) } }.flatten
  calls << Double.new
  calls << Redouble.new
  calls << Pass.new
  calls
end

.from_string(string) ⇒ Object

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bridge/call.rb', line 27

def self.from_string string
  string ||= ''
  call = nil
  case string.downcase
  when 'p','pass'
    call = Pass.new
  when 'd', 'double'
    call = Double.new
  when 'r', 'redouble'
    call = Redouble.new
  when /^bi?d? [a-z]{3,5} [a-z\s\_]{4,8}$/i
    bid = string.split
    bid.shift # get rid of 'bid'
    level = bid.shift
    strain = bid.join('_')
    call = Bid.new(level,strain)
  end
  raise CallError.new, "'#{string}' is not a call" if call.nil?
  call
end

Instance Method Details

#to_sObject



56
57
58
# File 'lib/bridge/call.rb', line 56

def to_s
  self.class.to_s.downcase.gsub('bridge::','')
end