ehbrs_ruby_utils 0.30.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb +17 -0
  3. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_option.rb +22 -0
  4. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player.rb +27 -0
  5. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb +68 -0
  6. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning/format_player.rb +24 -0
  7. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning.rb +35 -0
  8. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending/format_player.rb +32 -0
  9. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending.rb +45 -0
  10. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters.rb +13 -0
  11. data/lib/ehbrs_ruby_utils/gjt1/manager.rb +8 -5
  12. data/lib/ehbrs_ruby_utils/version.rb +1 -1
  13. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.target.yaml +20 -0
  14. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.source.html +8650 -0
  15. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.target.yaml +41 -0
  16. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.target.yaml +2 -0
  17. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.target.yaml +6 -0
  18. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.target.yaml +14 -0
  19. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.target.yaml +3 -0
  20. metadata +18 -15
  21. data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_option.rb +0 -18
  22. data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_player.rb +0 -30
  23. data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3802f6228037cca931f88ce749cf512aa19c4c2e62a6ce91f35e81a8ea3e5928
4
- data.tar.gz: 433ae6d2b1dc7133920a5a6c10dddf6ae2170aff8a1f5d5e03dd88dd978de1fd
3
+ metadata.gz: 5bfa52ff0a0f148ccb210785d37954b3b3e3e991a4fb3517bb78d23bc1a683c9
4
+ data.tar.gz: cc72969d634c6153c8841507fdc7582d1e004b52af6f6d6d1fc6cce0b5fff113
5
5
  SHA512:
6
- metadata.gz: 6c084798e36730906270e5ce96e9086527a75be3e5474af382ae03a67d2784aca2eb8ef110048f02fc5501f9113474eacbe3fd19f49491fbaf44f90393361fea
7
- data.tar.gz: 6fc1efe60241280dfe67da246075424285262d9ad1c24b3c467ac50aafd7b448388c5687e28b344e5061085ab55e0255ea885810bbfc0af4a7ca2d1aefc15abc
6
+ metadata.gz: bf06db90d4000d4a320e1832e1d02700d3c6d6ce302a1a47699dd5744a03aa07d3635389b56f4890ffb74e715842d0d4623143dc36ed01aceb5614a19e845723
7
+ data.tar.gz: ca8701c99fb083ff76ae8aad14cfd0e94f36f9e414e5a6fd570755dfe0e4feab816eeaf2ff98817f45db1e2a4ba14d8c60aa9ff756ccebf473ce2ebffea19d62
@@ -9,12 +9,29 @@ module EhbrsRubyUtils
9
9
  class GameInProgress < ::Aranha::Parsers::Html::ItemList
10
10
  ITEMS_XPATH = '//*[@id = "gametables_inprogress_all"]' \
11
11
  '//*[starts-with(@id, "gametableblock_")]'
12
+ STATUS_CLASS_PATTERN = /\Agametable_status_(.+)\z/.freeze
13
+ STATUS_CLASS_PARSER = STATUS_CLASS_PATTERN.to_parser { |m| m[1] }
12
14
 
13
15
  field :id, :integer, './@id'
16
+ field :status, :string, './@class'
17
+
18
+ def item_data(idd)
19
+ %i[status].each do |key|
20
+ idd[key] = send("process_#{key}", idd.fetch(key))
21
+ end
22
+ idd
23
+ end
14
24
 
15
25
  def items_xpath
16
26
  ITEMS_XPATH
17
27
  end
28
+
29
+ private
30
+
31
+ def process_status(status)
32
+ status.split(' ').lazy.map { |s| STATUS_CLASS_PARSER.parse(s.strip) }.find(&:present?) ||
33
+ raise("No status class found in \"#{status}\"")
34
+ end
18
35
  end
19
36
  end
20
37
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Table
8
+ module WhatsappFormatters
9
+ class Base
10
+ class FormatOption
11
+ acts_as_instance_method
12
+ common_constructor :table_formatter, :option
13
+
14
+ def result
15
+ "*#{option.label}:* #{option.value}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Table
8
+ module WhatsappFormatters
9
+ class Base
10
+ class FormatPlayer
11
+ acts_as_abstract :fields
12
+ acts_as_instance_method
13
+ common_constructor :table_formatter, :player
14
+
15
+ FIELD_SEPARATOR = ' - '
16
+
17
+ delegate :name, to: :player
18
+
19
+ def result
20
+ fields.map { |v| send(v) }.join(FIELD_SEPARATOR)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Table
8
+ module WhatsappFormatters
9
+ class Base
10
+ acts_as_abstract :players_title, :root_items_title, :title_icon
11
+ enable_simple_cache
12
+ common_constructor :table
13
+
14
+ PLAYERS_EXTRA = ''
15
+ ROOT_ITENS = {
16
+ 'Jogo' => :game_name,
17
+ 'Criada em' => :creation_time,
18
+ 'Duração' => :estimated_duration,
19
+ 'Endereço' => :url
20
+ }.freeze
21
+ SECTION_SEPARATOR = "\n\n"
22
+
23
+ # @return [Pathname]
24
+ def image_local_path
25
+ table.game.box_large_image.local_path
26
+ end
27
+
28
+ def to_s
29
+ [root_items_to_s, players_to_s, options_to_s].map(&:strip).join(SECTION_SEPARATOR)
30
+ end
31
+
32
+ def root_items_to_s
33
+ title_to_s(root_items_title) + ROOT_ITENS.map { |k, v| "*#{k}*: #{table.send(v)}" }
34
+ .join("\n")
35
+ end
36
+
37
+ def options_to_s
38
+ title_to_s('Opções') + options.join("\n")
39
+ end
40
+
41
+ # @return [String]
42
+ def players_extra
43
+ PLAYERS_EXTRA
44
+ end
45
+
46
+ # @return [String]
47
+ def players_to_s
48
+ title_to_s(players_title) + players_extra + players.join("\n")
49
+ end
50
+
51
+ def title_to_s(title)
52
+ '*' + [title_icon, title, title_icon].join(' ') + "*\n\n"
53
+ end
54
+
55
+ def players
56
+ table.players.map { |player| format_player(player) }
57
+ end
58
+
59
+ def options
60
+ table.options.map { |player| format_option(player) }
61
+ end
62
+
63
+ require_sub __FILE__, require_mode: :kernel
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player'
5
+
6
+ module EhbrsRubyUtils
7
+ module Bga
8
+ class Table
9
+ module WhatsappFormatters
10
+ class Beginning < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
11
+ class FormatPlayer < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base::FormatPlayer
12
+ acts_as_instance_method
13
+
14
+ FIELDS = %w[name].freeze
15
+
16
+ def fields
17
+ FIELDS
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base'
5
+
6
+ module EhbrsRubyUtils
7
+ module Bga
8
+ class Table
9
+ module WhatsappFormatters
10
+ class Beginning < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
11
+ PLAYERS_TITLE = 'Jogadores'
12
+ ROOT_ITEMS_TITLE = 'Mesa iniciada'
13
+ TITLE_ICON = 0x2694.chr(::Encoding::UTF_8)
14
+
15
+ # @return [String]
16
+ def players_title
17
+ PLAYERS_TITLE
18
+ end
19
+
20
+ # @return [String]
21
+ def root_items_title
22
+ ROOT_ITEMS_TITLE
23
+ end
24
+
25
+ # @return [String]
26
+ def title_icon
27
+ TITLE_ICON
28
+ end
29
+
30
+ require_sub __FILE__, require_mode: :kernel
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player'
5
+
6
+ module EhbrsRubyUtils
7
+ module Bga
8
+ class Table
9
+ module WhatsappFormatters
10
+ class Ending < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
11
+ class FormatPlayer < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base::FormatPlayer
12
+ acts_as_instance_method
13
+
14
+ FIELDS = %w[table_rank name score].freeze
15
+
16
+ def fields
17
+ FIELDS
18
+ end
19
+
20
+ def table_rank
21
+ "*#{player.rank}º*"
22
+ end
23
+
24
+ def score
25
+ "⭐ #{player.score}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base'
5
+
6
+ module EhbrsRubyUtils
7
+ module Bga
8
+ class Table
9
+ module WhatsappFormatters
10
+ class Ending < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
11
+ PLAYERS_TITLE = 'Resultado'
12
+ ROOT_ITEMS_TITLE = 'Mesa terminada'
13
+ TITLE_ICON = 0x1F3C6.chr(::Encoding::UTF_8)
14
+
15
+ # @return [String]
16
+ def game_conceded_to_s
17
+ table.game_conceded? ? "*Derrota admitida*\n\n" : ''
18
+ end
19
+
20
+ # @return [String]
21
+ def players_extra
22
+ game_conceded_to_s
23
+ end
24
+
25
+ # @return [String]
26
+ def players_title
27
+ PLAYERS_TITLE
28
+ end
29
+
30
+ # @return [String]
31
+ def root_items_title
32
+ ROOT_ITEMS_TITLE
33
+ end
34
+
35
+ # @return [String]
36
+ def title_icon
37
+ TITLE_ICON
38
+ end
39
+
40
+ require_sub __FILE__, require_mode: :kernel
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Table
8
+ module WhatsappFormatters
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -11,11 +11,14 @@ module EhbrsRubyUtils
11
11
  include ::Singleton
12
12
  acts_as_abstract :bga_usernam, :bga_password, :whatsapp_recipient
13
13
 
14
- # @param table [EhbrsRubyUtils::Bga::Table]
15
- # @return [void]
16
- def bga_table_notify(table)
17
- formatter = ::EhbrsRubyUtils::Bga::TableWhatsappFormatter.new(table)
18
- whatsapp_send(formatter.to_s, formatter.image_local_path)
14
+ %w[beginning ending].each do |type|
15
+ # @param table [EhbrsRubyUtils::Bga::Table]
16
+ # @return [void]
17
+ define_method "bga_table_#{type}_notify" do |table|
18
+ formatter = ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters.const_get(type.camelize)
19
+ .new(table)
20
+ whatsapp_send(formatter.to_s, formatter.image_local_path)
21
+ end
19
22
  end
20
23
 
21
24
  def on_bga_logged_session(&block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.30.0'
4
+ VERSION = '0.32.0'
5
5
  end
@@ -1,21 +1,41 @@
1
1
  ---
2
2
  - :id: 386538047
3
+ :status: asyncplay
3
4
  - :id: 386107349
5
+ :status: asyncplay
4
6
  - :id: 385834996
7
+ :status: asyncplay
5
8
  - :id: 385698263
9
+ :status: asyncplay
6
10
  - :id: 385694780
11
+ :status: asyncplay
7
12
  - :id: 385359528
13
+ :status: asyncplay
8
14
  - :id: 384903532
15
+ :status: asyncplay
9
16
  - :id: 384212341
17
+ :status: asyncplay
10
18
  - :id: 383714070
19
+ :status: asyncplay
11
20
  - :id: 383403753
21
+ :status: asyncplay
12
22
  - :id: 383405743
23
+ :status: asyncplay
13
24
  - :id: 382781153
25
+ :status: asyncplay
14
26
  - :id: 382715267
27
+ :status: asyncplay
15
28
  - :id: 378760639
29
+ :status: asyncplay
16
30
  - :id: 378760858
31
+ :status: asyncplay
17
32
  - :id: 378698179
33
+ :status: asyncplay
18
34
  - :id: 378397710
35
+ :status: asyncplay
19
36
  - :id: 377545689
37
+ :status: asyncplay
20
38
  - :id: 377079104
39
+ :status: asyncplay
21
40
  - :id: 375601108
41
+ :status: asyncplay