Class: Ficsr::Game
- Inherits:
-
Object
- Object
- Ficsr::Game
- Defined in:
- lib/ficsr/game.rb
Instance Attribute Summary collapse
-
#black_handle ⇒ Object
Returns the value of attribute black_handle.
-
#black_rating ⇒ Object
Returns the value of attribute black_rating.
-
#category_id ⇒ Object
Returns the value of attribute category_id.
-
#increment_seconds ⇒ Object
Returns the value of attribute increment_seconds.
-
#move_number ⇒ Object
Returns the value of attribute move_number.
-
#number ⇒ Object
Returns the value of attribute number.
-
#private ⇒ Object
Returns the value of attribute private.
-
#rated ⇒ Object
Returns the value of attribute rated.
-
#start_minutes ⇒ Object
Returns the value of attribute start_minutes.
-
#strength_black ⇒ Object
Returns the value of attribute strength_black.
-
#strength_white ⇒ Object
Returns the value of attribute strength_white.
-
#time_black ⇒ Object
Returns the value of attribute time_black.
-
#time_white ⇒ Object
Returns the value of attribute time_white.
-
#turn ⇒ Object
Returns the value of attribute turn.
-
#white_handle ⇒ Object
Returns the value of attribute white_handle.
-
#white_rating ⇒ Object
Returns the value of attribute white_rating.
Instance Method Summary collapse
- #category ⇒ Object
-
#initialize(game_def) ⇒ Game
constructor
A new instance of Game.
- #private? ⇒ Boolean
- #rated? ⇒ Boolean
- #whites_turn? ⇒ Boolean
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. = match_data[:white_rating] self.white_handle = match_data[:white_handle] self. = 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_handle ⇒ Object
Returns the value of attribute black_handle.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def black_handle @black_handle end |
#black_rating ⇒ Object
Returns the value of attribute black_rating.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def @black_rating end |
#category_id ⇒ Object
Returns the value of attribute category_id.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def category_id @category_id end |
#increment_seconds ⇒ Object
Returns the value of attribute increment_seconds.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def increment_seconds @increment_seconds end |
#move_number ⇒ Object
Returns the value of attribute move_number.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def move_number @move_number end |
#number ⇒ Object
Returns the value of attribute number.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def number @number end |
#private ⇒ Object
Returns the value of attribute private.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def private @private end |
#rated ⇒ Object
Returns the value of attribute rated.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def rated @rated end |
#start_minutes ⇒ Object
Returns the value of attribute start_minutes.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def start_minutes @start_minutes end |
#strength_black ⇒ Object
Returns the value of attribute strength_black.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def strength_black @strength_black end |
#strength_white ⇒ Object
Returns the value of attribute strength_white.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def strength_white @strength_white end |
#time_black ⇒ Object
Returns the value of attribute time_black.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def time_black @time_black end |
#time_white ⇒ Object
Returns the value of attribute time_white.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def time_white @time_white end |
#turn ⇒ Object
Returns the value of attribute turn.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def turn @turn end |
#white_handle ⇒ Object
Returns the value of attribute white_handle.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def white_handle @white_handle end |
#white_rating ⇒ Object
Returns the value of attribute white_rating.
56 57 58 |
# File 'lib/ficsr/game.rb', line 56 def @white_rating end |
Instance Method Details
#category ⇒ Object
62 63 64 |
# File 'lib/ficsr/game.rb', line 62 def category CATEGORIES[self.category_id] end |
#private? ⇒ Boolean
58 59 60 |
# File 'lib/ficsr/game.rb', line 58 def private? self.private end |
#rated? ⇒ Boolean
66 67 68 |
# File 'lib/ficsr/game.rb', line 66 def rated? self.rated == "r" end |
#whites_turn? ⇒ Boolean
70 71 72 |
# File 'lib/ficsr/game.rb', line 70 def whites_turn? self.turn == "W" end |