Class: EhbrsRubyUtils::Bga::Table
- Inherits:
-
Object
- Object
- EhbrsRubyUtils::Bga::Table
show all
- Includes:
- Urls
- Defined in:
- lib/ehbrs_ruby_utils/bga/table.rb,
lib/ehbrs_ruby_utils/bga/table/option.rb,
lib/ehbrs_ruby_utils/bga/table/player.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_option.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending/format_player.rb,
lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning/format_player.rb
Defined Under Namespace
Modules: WhatsappFormatters
Classes: Option, Player
Constant Summary
collapse
- GAME_MODE_KEYS =
['Modo do jogo', 'Modo de Jogo'].freeze
- GAME_MODE_FRIENDLY_VALUE =
'Modo Amigável'
- GAME_MODE_NORMAL_VALUE =
'Modo Normal'
- SET_ITEMS =
%i[options players].freeze
Urls::InstanceMethods::ROOT_URL
Instance Method Summary
collapse
#build_url, #player_game_in_progress_url, #player_game_stats_url, #root_url, #table_url
Instance Method Details
#friendly? ⇒ Boolean
24
25
26
27
28
29
30
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 24
def friendly?
value = game_mode_value
return true if value == GAME_MODE_FRIENDLY_VALUE
return false if value == GAME_MODE_NORMAL_VALUE
raise "Unknown value for game mode: \"#{value}\" (Options: #{options_to_s})"
end
|
#game_conceded? ⇒ Boolean
33
34
35
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 33
def game_conceded?
game_conceded
end
|
#game_mode_value ⇒ String
38
39
40
41
42
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 38
def game_mode_value
GAME_MODE_KEYS.lazy.map { |k| option_value(k) }.find(&:present?) ||
raise("No option found with one of the labels #{GAME_MODE_KEYS} " \
"(Options: #{options_to_s})")
end
|
#option_value(label) ⇒ String?
51
52
53
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 51
def option_value(label)
options.find { |o| o.label == label }.if_present(&:value)
end
|
#options_to_s ⇒ String
45
46
47
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 45
def options_to_s
options.map { |o| "#{o.label}=\"#{o.value}\"" }.join(', ')
end
|
57
58
59
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 57
def player_by_id(id)
players.find { |p| p.id.to_s == id.to_s }
end
|
#url ⇒ Addressable::URI
62
63
64
|
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 62
def url
table_url(id)
end
|