Class: Bridge::Points::Chicago

Inherits:
Object
  • Object
show all
Defined in:
lib/bridge/constants.rb,
lib/bridge/points/chicago.rb

Constant Summary collapse

POINTS =

values in array: [not-vulnerable, vulnerable]

{
  20 => [0,    0],
  21 => [50,   50],
  22 => [70,   70],
  23 => [110,  110],
  24 => [200,  290],
  25 => [300,  440],
  26 => [350,  520],
  27 => [400,  600],
  28 => [430,  630],
  29 => [460,  660],
  30 => [490,  690],
  31 => [600,  900],
  32 => [700,  1050],
  33 => [900,  1350],
  34 => [1000, 1500],
  35 => [1100, 1650],
  36 => [1200, 1800],
  37 => [1300, 1950],
  38 => [1300, 1950],
  39 => [1300, 1950],
  40 => [1300, 1950]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Chicago

Creates new Imp object

Example

Bridge::Points::Chicago.new(:hcp => 25, :points => 420, :vulnerable => true)

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/bridge/points/chicago.rb', line 10

def initialize(options = {})
  @hcp = options[:hcp]
  raise ArgumentError, "Invalid hcp: #{hcp} - value should be between 20 and 40" unless (20..40).include?(hcp)
  @points = options[:points]
  @vulnerable = options[:vulnerable] || false
end

Instance Attribute Details

#hcpObject (readonly)

Returns the value of attribute hcp.



3
4
5
# File 'lib/bridge/points/chicago.rb', line 3

def hcp
  @hcp
end

#pointsObject (readonly)

Returns the value of attribute points.



3
4
5
# File 'lib/bridge/points/chicago.rb', line 3

def points
  @points
end

#vulnerableObject (readonly) Also known as: vulnerable?

Returns the value of attribute vulnerable.



3
4
5
# File 'lib/bridge/points/chicago.rb', line 3

def vulnerable
  @vulnerable
end

Instance Method Details

#impsObject

Returns imps (negative or positive) based on given points



28
29
30
# File 'lib/bridge/points/chicago.rb', line 28

def imps
  Bridge::Points.imps(points_difference)
end

#points_differenceObject

Returns points score relative to hcp



23
24
25
# File 'lib/bridge/points/chicago.rb', line 23

def points_difference
  points - points_to_make
end

#points_to_makeObject

Returns points that side should make with given hcp



18
19
20
# File 'lib/bridge/points/chicago.rb', line 18

def points_to_make
  POINTS[hcp][vulnerable? ? 1 : 0]
end