Class: AcpcTableManager::ExhibitionConfig

Inherits:
Object
  • Object
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

Constructor Details

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

Returns a new instance of ExhibitionConfig.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/acpc_table_manager/config.rb', line 47

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



45
46
47
# File 'lib/acpc_table_manager/config.rb', line 45

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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/acpc_table_manager/config.rb', line 70

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