Class: AcpcTableManager::ExhibitionConfig

Inherits:
NilDefaultConfig show all
Includes:
SimpleLogging
Defined in:
lib/acpc_table_manager/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleLogging

#log, #log_with, #logger

Methods inherited from NilDefaultConfig

#method_missing

Constructor Details

#initialize(file_path, interpolation_hash, logger = Logger.new(STDOUT)) ⇒ ExhibitionConfig

Returns a new instance of ExhibitionConfig.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/acpc_table_manager/config.rb', line 52

def initialize(file_path, interpolation_hash, logger = Logger.new(STDOUT))
  @logger = logger
  @file = file_path
  JSON.parse(File.read(file_path)).each do |constant, val|
    interpolated_val = ::AcpcTableManager.interpolate_all_strings(val, interpolation_hash)
    log(__method__, {adding: {method: constant, value: interpolated_val}})

    instance_variable_set("@#{constant}".to_sym, interpolated_val)
    define_singleton_method(constant.to_sym) do
      instance_variable_get("@#{constant}".to_sym)
    end
  end
  unless special_ports_to_dealer
    @special_ports_to_dealer = []
    log(__method__, {adding: {method: 'special_ports_to_dealer', value: @special_ports_to_dealer}})
    define_singleton_method(:special_ports_to_dealer) do
      instance_variable_get(:@special_ports_to_dealer)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AcpcTableManager::NilDefaultConfig

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



50
51
52
# File 'lib/acpc_table_manager/config.rb', line 50

def file
  @file
end

Instance Method Details

#bots(game_def_key, *player_names) ⇒ Array<Class>

Returns only the names that correspond to bot runner classes as those classes.

Returns:

  • (Array<Class>)

    Returns only the names that correspond to bot runner classes as those classes.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/acpc_table_manager/config.rb', line 75

def bots(game_def_key, *player_names)
  game_def_key = game_def_key.to_s
  if @games[game_def_key]
    if @games[game_def_key]['opponents']
      player_names.reduce({}) do |bot_map, name|
        bot_map[name] = @games[game_def_key]['opponents'][name] if @games[game_def_key]['opponents'][name]
        bot_map
      end
    else
      log(__method__, {warning: "Game '#{game_def_key}' has no opponents."}, Logger::Severity::WARN)
      {}
    end
  else
    log(__method__, {warning: "Unrecognized game, '#{game_def_key}'."}, Logger::Severity::WARN)
    {}
  end
end