Class: EhbrsRubyUtils::Bga::TableWhatsappFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb,
lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_option.rb,
lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_player.rb

Defined Under Namespace

Classes: FormatOption, FormatPlayer

Constant Summary collapse

TITLE_BEFORE =
0x22D8.chr(::Encoding::UTF_8) + ' '
TITLE_AFTER =
' ' + 0x22D9.chr(::Encoding::UTF_8)
ROOT_ITENS =
{
  'Jogo' => :game_name,
  'Criada em' => :creation_time,
  'Duração' => :estimated_duration,
  'Endereço' => :url
}.freeze
SECTION_SEPARATOR =
"\n\n"

Instance Method Summary collapse

Instance Method Details

#game_conceded_to_sString

Returns:

  • (String)


39
40
41
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 39

def game_conceded_to_s
  table.game_conceded? ? "*Derrota admitida*\n\n" : ''
end

#optionsObject



59
60
61
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 59

def options
  table.options.map { |player| format_option(player) }
end

#options_to_sObject



47
48
49
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 47

def options_to_s
  title_to_s('Opções') + options.join("\n")
end

#performObject



24
25
26
27
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 24

def perform
  infov 'Fetching table', table_id
  infov 'Message', "<<<EOS\n#{to_message}\nEOS\n"
end

#playersObject



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

def players
  table.players.map { |player| format_player(player) }
end

#players_to_sObject



43
44
45
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 43

def players_to_s
  title_to_s('Resultado') + game_conceded_to_s + players.join("\n")
end

#root_items_to_sObject



33
34
35
36
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 33

def root_items_to_s
  title_to_s('Mesa terminada') + ROOT_ITENS.map { |k, v| "*#{k}*: #{table.send(v)}" }
                                   .join("\n")
end

#title_to_s(title) ⇒ Object



51
52
53
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 51

def title_to_s(title)
  "*#{TITLE_BEFORE}#{title}#{TITLE_AFTER}*\n\n"
end

#to_sObject



29
30
31
# File 'lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb', line 29

def to_s
  [root_items_to_s, players_to_s, options_to_s].map(&:strip).join(SECTION_SEPARATOR)
end