Class: Lin::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lin/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



7
8
9
# File 'lib/lin/parser.rb', line 7

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/lin/parser.rb', line 5

def source
  @source
end

Instance Method Details

#bidsArray<String>

Returns bids

Returns:

  • (Array<String>)


89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/lin/parser.rb', line 89

def bids
  @bids ||= parsed["mb"].map do |bid|
    case bid.upcase
    when "P" then "PASS"
    when "D" then "X"
    when "R" then "XX"
    when /\dN/ then bid[0] + "NT"
    else
      bid.upcase
    end
  end
end

#board_nameString

Returns board name

Returns:

  • (String)


70
71
72
# File 'lib/lin/parser.rb', line 70

def board_name
  @board_name ||= parsed["ah"][0]
end

#cardsArray<String>

Returns played cards

Returns:

  • (Array<String>)


105
106
107
# File 'lib/lin/parser.rb', line 105

def cards
  @cards ||= parsed["pc"]
end

#claimInteger?

Returns claimed number of tricks

Returns:

  • (Integer, nil)


112
113
114
# File 'lib/lin/parser.rb', line 112

def claim
  @claim ||= parsed["mc"][0] && parsed["mc"][0].to_i
end

#dealer"N", ...

Returns dealer

Returns:

  • ("N", "E", "S", "W")


77
78
79
80
81
82
83
84
# File 'lib/lin/parser.rb', line 77

def dealer
  @dealer ||= case parsed["md"][0][0]
  when "1" then "S"
  when "2" then "W"
  when "3" then "N"
  when "4" then "E"
  end
end

#eArray<String>

Returns cards for E hand

Returns:

  • (Array<String>)


35
36
37
# File 'lib/lin/parser.rb', line 35

def e
  @e ||= deck - s - w - n
end

#e_nameString

Returns E player name

Returns:

  • (String)


63
64
65
# File 'lib/lin/parser.rb', line 63

def e_name
  @e_name ||= players[3]
end

#nArray<String>

Returns cards for N hand

Returns:

  • (Array<String>)


28
29
30
# File 'lib/lin/parser.rb', line 28

def n
  @n ||= parse_hand(parsed["md"][0].split(",")[2])
end

#n_nameString

Returns N player name

Returns:

  • (String)


56
57
58
# File 'lib/lin/parser.rb', line 56

def n_name
  @n_name ||= players[2]
end

#sArray<String>

Returns cards for S hand

Returns:

  • (Array<String>)


14
15
16
# File 'lib/lin/parser.rb', line 14

def s
  @s ||= parse_hand(parsed["md"][0].split(",")[0][1..-1])
end

#s_nameString

Returns S player name

Returns:

  • (String)


42
43
44
# File 'lib/lin/parser.rb', line 42

def s_name
  @s_name ||= players[0]
end

#vulnerable"NONE" "NS", ...

Returns vulnerable

Returns:

  • ("NONE" "NS", "EW", "BOTH")


119
120
121
122
123
124
125
126
127
# File 'lib/lin/parser.rb', line 119

def vulnerable
  @vulnerable ||= case parsed["sv"][0]
  when "n" then "NS"
  when "e" then "EW"
  when "b" then "BOTH"
  else
    "NONE"
  end
end

#wArray<String>

Returns cards for W hand

Returns:

  • (Array<String>)


21
22
23
# File 'lib/lin/parser.rb', line 21

def w
  @w ||= parse_hand(parsed["md"][0].split(",")[1])
end

#w_nameString

Returns W player name

Returns:

  • (String)


49
50
51
# File 'lib/lin/parser.rb', line 49

def w_name
  @w_name ||= players[1]
end