Class: EhbrsRubyUtils::Bga::Table

Inherits:
Object
  • Object
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.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_KEY =
'Modo de Jogo'
GAME_MODE_FRIENDLY_VALUE =
'Modo Amigável'
GAME_MODE_NORMAL_VALUE =
'Modo Normal'
SET_ITEMS =
%i[options players].freeze

Constants included from Urls::InstanceMethods

Urls::InstanceMethods::ROOT_URL

Instance Method Summary collapse

Methods included from Urls::InstanceMethods

#build_url, #player_game_in_progress_url, #player_game_stats_url, #root_url, #table_url

Instance Method Details

#friendly?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 29

def friendly?
  value = option_value(GAME_MODE_KEY)
  return true if value == GAME_MODE_FRIENDLY_VALUE
  return false if value == GAME_MODE_NORMAL_VALUE

  raise "Unknown \"#{GAME_MODE_KEY}\" value: \"#{value}\""
end

#game_conceded?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 38

def game_conceded?
  game_conceded
end

#option_value(label) ⇒ String?

Parameters:

  • key (String)

Returns:

  • (String, nil)


44
45
46
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 44

def option_value(label)
  options.find { |o| o.label == label }.if_present(&:value)
end

#player_by_id(id) ⇒ EhbrsRubyUtils::Bga::Table::Player?

Parameters:

  • id (Integer)

Returns:



50
51
52
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 50

def player_by_id(id)
  players.find { |p| p.id.to_s == id.to_s }
end

#urlAddressable::URI

Returns:

  • (Addressable::URI)


55
56
57
# File 'lib/ehbrs_ruby_utils/bga/table.rb', line 55

def url
  table_url(id)
end