Class: Ficsr::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/ficsr/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_def) ⇒ Game

Returns a new instance of Game.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ficsr/game.rb', line 8

def initialize(game_def)
  game_regexp = %r{
  (?<number>^\d*){0}
  (?<white_rating>\S*){0}                  
  (?<white_handle>\S*){0}                  
  (?<black_rating>\S*){0}                  
  (?<black_handle>\S*){0}                  
  (?<private>p?){0}                  
  (?<category>\w?){0}                  
  (?<rated>\w?){0}                  
  (?<start_minutes>\d*){0}                  
  (?<increment_seconds>\d*){0}                  
  (?<time_white>\d*:\d*:?\d*){0}                  
  (?<time_black>\d*:\d*:?\d*){0}                  
  (?<strength_white>\d*){0}                  
  (?<strength_black>\d*){0}                  
  (?<turn>[WB]){0}                  
  (?<move_number>\d*){0}                  
  
  \g<number>\s*\g<white_rating>\s*\g<white_handle>\s*\g<black_rating>\s*\g<black_handle>\s*\[\g<private>\s*
  \g<category>\s*\g<rated>\s*\g<start_minutes>\s*\g<increment_seconds>\]\s*\g<time_white>\s*-\s*
  \g<time_black>\s*\(\s*\g<strength_white>\s*-\s*\g<strength_black>\)\s\g<turn>:\s*\g<move_number>$
  
  }x

  match_data = game_def.match(game_regexp)
  if match_data
    self.number             = match_data[:number].to_i
    self.white_rating       = match_data[:white_rating]
    self.white_handle       = match_data[:white_handle]
    self.black_rating       = match_data[:black_rating]
    self.black_handle       = match_data[:black_handle]
    self.private            = !match_data[:private].empty?
    self.category_id        = match_data[:category].to_sym
    self.rated              = match_data[:rated]
    self.start_minutes      = match_data[:start_minutes].to_i
    self.increment_seconds  = match_data[:increment_seconds].to_i
    self.time_white         = match_data[:time_white]
    self.time_black         = match_data[:time_black]
    self.strength_white     = match_data[:strength_white].to_i
    self.strength_black     = match_data[:strength_black].to_i
    self.turn               = match_data[:turn]
    self.move_number        = match_data[:move_number].to_i
  else
    p "ignoring game '#{game_def}'"
  end
end

Instance Attribute Details

#black_handleObject

Returns the value of attribute black_handle.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def black_handle
  @black_handle
end

#black_ratingObject

Returns the value of attribute black_rating.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def black_rating
  @black_rating
end

#category_idObject

Returns the value of attribute category_id.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def category_id
  @category_id
end

#increment_secondsObject

Returns the value of attribute increment_seconds.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def increment_seconds
  @increment_seconds
end

#move_numberObject

Returns the value of attribute move_number.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def move_number
  @move_number
end

#numberObject

Returns the value of attribute number.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def number
  @number
end

#privateObject

Returns the value of attribute private.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def private
  @private
end

#ratedObject

Returns the value of attribute rated.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def rated
  @rated
end

#start_minutesObject

Returns the value of attribute start_minutes.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def start_minutes
  @start_minutes
end

#strength_blackObject

Returns the value of attribute strength_black.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def strength_black
  @strength_black
end

#strength_whiteObject

Returns the value of attribute strength_white.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def strength_white
  @strength_white
end

#time_blackObject

Returns the value of attribute time_black.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def time_black
  @time_black
end

#time_whiteObject

Returns the value of attribute time_white.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def time_white
  @time_white
end

#turnObject

Returns the value of attribute turn.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def turn
  @turn
end

#white_handleObject

Returns the value of attribute white_handle.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def white_handle
  @white_handle
end

#white_ratingObject

Returns the value of attribute white_rating.



56
57
58
# File 'lib/ficsr/game.rb', line 56

def white_rating
  @white_rating
end

Instance Method Details

#categoryObject



62
63
64
# File 'lib/ficsr/game.rb', line 62

def category
  CATEGORIES[self.category_id]
end

#private?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ficsr/game.rb', line 58

def private?
  self.private
end

#rated?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ficsr/game.rb', line 66

def rated?
  self.rated == "r"
end

#whites_turn?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ficsr/game.rb', line 70

def whites_turn?
  self.turn == "W"
end