OSDN Git Service

- shogi-server, shogi_server/league/floodgate.rb: Changed the argument of Floodgate...
[shogi-server/shogi-server.git] / shogi_server / league / floodgate.rb
index f780cc8..4f6ac2b 100644 (file)
@@ -16,12 +16,17 @@ class League
 
     attr_reader :next_time, :league
 
-    def initialize(league, next_time=nil)
+    def initialize(league, hash={})
       @league = league
-      @next_time = next_time
+      @next_time = hash[:next_time] || nil
+      @game_name = hash[:game_name] || "floodgate-900-0"
       charge
     end
 
+    def game_name?(str)
+      return Regexp.new(@game_name).match(str) ? true : false
+    end
+
     def charge
       now = Time.now
       unless $DEBUG
@@ -44,7 +49,7 @@ class League
     def match_game
       players = @league.find_all_players do |pl|
         pl.status == "game_waiting" &&
-        Floodgate.game_name?(pl.game_name) &&
+        game_name?(pl.game_name) &&
         pl.sente == nil
       end
       Pairing.match(players)
@@ -67,7 +72,8 @@ class League
 
       attr_reader :records
 
-      # file_path_name is a Pathname object for this storage
+      # Initialize this instance.
+      # @param file_path_name a Pathname object for this storage
       #
       def initialize(file_path_name)
         @records = []
@@ -104,7 +110,7 @@ class League
         @records = YAML.load_file(@file)
         unless @records && @records.instance_of?(Array)
           $logger.error "%s is not a valid yaml file. Instead, an empty array will be used and updated." % [@file]
-          @records = [].to_yaml
+          @records = []
         end
       end