ehbrs_ruby_utils 0.24.1 → 0.25.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef922dc8e609ca372c63e29cbfda768e95abc03b24c0fd5b9a5c6d46bf707445
4
- data.tar.gz: ad3022d2b588614b4471798f751a8edca0800e301ab0f7bd689a22fc684fd59f
3
+ metadata.gz: 3c7b8c03f444eeecd6bc0cf3294b7fdb87d853e794d882a33075fc144d6e0643
4
+ data.tar.gz: 6d9ea47d713deb5f42930df49bf59beaa5d7feeadcaf1f317c2f72265e5645ac
5
5
  SHA512:
6
- metadata.gz: f2e2052b2490544bcb9edd3234d082f46489aa76d277889d33cc75ad75e31e9181c1c38deb00b4741723ba396be7c0f2ebbe71931845fd7db4145cfffe60dd00
7
- data.tar.gz: 4b27d92bade1d8a85151dbd2ce9c101286b75c433327a849fbab1bb275ce47e4c6b06c850616b320480b18ea294b59c76b55199023e80bcb38c7da465d4c54c1
6
+ metadata.gz: 337fc2b2871c7546da3c36e7362463541466f77f94a32ac7813c68692dce1c0e0883d6dd765bbc1b0226a502ed0a9049f6b49debbf920f68d370e2b478ead4b5
7
+ data.tar.gz: db9aefd67166403008410368a68b5bde75777b3d819b7e0c829fb0b83a687af08f7b3e320ce2d840a0cfd38abaca8fbdf036adc785c3de4fbe8ae9451e5a4241
@@ -1,26 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ehbrs_ruby_utils/bga/parsers/game_stats'
4
- require 'ehbrs_ruby_utils/bga/urls'
5
3
  require 'eac_ruby_utils/core_ext'
6
4
 
7
5
  module EhbrsRubyUtils
8
6
  module Bga
9
7
  class Session < ::SimpleDelegator
10
8
  class Player
11
- include ::EhbrsRubyUtils::Bga::Urls
12
- GAME_HISTORY_XPATH = '//h3[text() = "Games history"]'
13
9
  common_constructor :session, :player_id
14
10
 
15
11
  def tables
16
- session.navigate.to game_stats_url
17
- session.wait_for_element(xpath: GAME_HISTORY_XPATH)
18
- ::EhbrsRubyUtils::Bga::Parsers::GameStats.from_content(session.current_source).data
19
- end
20
-
21
- # @return [Addressable::URI]
22
- def game_stats_url
23
- session.url("/gamestats?player=#{player_id}")
12
+ session.player_tables_on_game_stats(player_id)
24
13
  end
25
14
  end
26
15
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ehbrs_ruby_utils/bga/parsers/table'
4
- require 'ehbrs_ruby_utils/bga/table'
3
+ require 'ehbrs_ruby_utils/bga/parsers/game_stats'
5
4
  require 'ehbrs_ruby_utils/bga/urls'
6
5
  require 'eac_ruby_utils/core_ext'
7
6
 
@@ -56,7 +55,7 @@ module EhbrsRubyUtils
56
55
  def list_end_reached?
57
56
  previous_count = current_data.count
58
57
  result = nil
59
- session.wait_for_click(id: SEE_MORE_BUTTON_ID)
58
+ session.on_skip_trophies { session.wait_for_click(id: SEE_MORE_BUTTON_ID) }
60
59
  session.wait.until do
61
60
  result = list_end_reached_non_waiting(previous_count)
62
61
  !result.nil?
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Session < ::SimpleDelegator
8
+ module SkipTrophies
9
+ TROPHY_SKIP_BUTTON_XPATH = '//*[@id = "splashedNotifications_overlay"]' \
10
+ '//*[starts-with(@id, "continue_btn_")]'
11
+ TROPHY_SKIP_TIMEOUT = 5
12
+
13
+ # @param &block [Proc]
14
+ # @return [Selenium::WebDriver::Error::TimeoutError, nil]
15
+ def on_rescue_timeout(&block)
16
+ block.call
17
+ nil
18
+ rescue ::Selenium::WebDriver::Error::TimeoutError => e
19
+ e
20
+ end
21
+
22
+ def on_skip_trophies(&block)
23
+ error = on_rescue_timeout(&block)
24
+ return unless error
25
+ raise error unless skip_trophy_overlay?
26
+
27
+ skip_trophies
28
+ end
29
+
30
+ def skip_trophies
31
+ loop do
32
+ wait_for_click({ xpath: TROPHY_SKIP_BUTTON_XPATH }, TROPHY_SKIP_TIMEOUT)
33
+ rescue ::Selenium::WebDriver::Error::TimeoutError
34
+ break
35
+ end
36
+ end
37
+
38
+ # @return [Boolean]
39
+ def skip_trophy_overlay?
40
+ find_element(xpath: TROPHY_SKIP_BUTTON_XPATH).present?
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class TableWhatsappFormatter
8
+ class FormatOption
9
+ enable_method_class
10
+ common_constructor :table_formatter, :option
11
+
12
+ def result
13
+ "*#{option.label}:* #{option.value}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class TableWhatsappFormatter
8
+ class FormatPlayer
9
+ enable_method_class
10
+ common_constructor :table_formatter, :player
11
+
12
+ FIELD_SEPARATOR = ' - '
13
+
14
+ def result
15
+ %w[table_rank name score].map { |v| send(v) }.join(FIELD_SEPARATOR)
16
+ end
17
+
18
+ def table_rank
19
+ "*#{player.table_rank}º*"
20
+ end
21
+
22
+ delegate :name, to: :player
23
+
24
+ def score
25
+ "⭐ #{player.score}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/bga/session'
4
+ require 'ehbrs_ruby_utils/executables'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module Bga
9
+ class TableWhatsappFormatter
10
+ enable_simple_cache
11
+ common_constructor :table
12
+
13
+ TITLE_BEFORE = 0x22D8.chr(::Encoding::UTF_8) + ' '
14
+ TITLE_AFTER = ' ' + 0x22D9.chr(::Encoding::UTF_8)
15
+
16
+ ROOT_ITENS = {
17
+ 'Jogo' => :game_name,
18
+ 'Criada em' => :creation_time,
19
+ 'Duração' => :estimated_duration,
20
+ 'Endereço' => :url
21
+ }.freeze
22
+ SECTION_SEPARATOR = "\n\n"
23
+
24
+ def perform
25
+ infov 'Fetching table', table_id
26
+ infov 'Message', "<<<EOS\n#{to_message}\nEOS\n"
27
+ end
28
+
29
+ def to_s
30
+ [root_items_to_s, players_to_s, options_to_s].map(&:strip).join(SECTION_SEPARATOR)
31
+ end
32
+
33
+ def root_items_to_s
34
+ title_to_s('Mesa terminada') + ROOT_ITENS.map { |k, v| "*#{k}*: #{table.send(v)}" }
35
+ .join("\n")
36
+ end
37
+
38
+ # @return [String]
39
+ def game_conceded_to_s
40
+ table.game_conceded? ? "*Derrota admitida*\n\n" : ''
41
+ end
42
+
43
+ def players_to_s
44
+ title_to_s('Resultado') + game_conceded_to_s + players.join("\n")
45
+ end
46
+
47
+ def options_to_s
48
+ title_to_s('Opções') + options.join("\n")
49
+ end
50
+
51
+ def title_to_s(title)
52
+ "*#{TITLE_BEFORE}#{title}#{TITLE_AFTER}*\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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.24.1'
4
+ VERSION = '0.25.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-23 00:00:00.000000000 Z
11
+ date: 2023-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha
@@ -37,6 +37,9 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.19'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.19.1
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,20 +47,37 @@ dependencies:
44
47
  - - "~>"
45
48
  - !ruby/object:Gem::Version
46
49
  version: '0.19'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.19.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: aranha-selenium
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.6'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.6'
47
67
  - !ruby/object:Gem::Dependency
48
68
  name: avm
49
69
  requirement: !ruby/object:Gem::Requirement
50
70
  requirements:
51
71
  - - "~>"
52
72
  - !ruby/object:Gem::Version
53
- version: '0.75'
73
+ version: '0.76'
54
74
  type: :runtime
55
75
  prerelease: false
56
76
  version_requirements: !ruby/object:Gem::Requirement
57
77
  requirements:
58
78
  - - "~>"
59
79
  - !ruby/object:Gem::Version
60
- version: '0.75'
80
+ version: '0.76'
61
81
  - !ruby/object:Gem::Dependency
62
82
  name: eac_fs
63
83
  requirement: !ruby/object:Gem::Requirement
@@ -206,10 +226,14 @@ files:
206
226
  - lib/ehbrs_ruby_utils/bga/session/login.rb
207
227
  - lib/ehbrs_ruby_utils/bga/session/player.rb
208
228
  - lib/ehbrs_ruby_utils/bga/session/player_tables_on_game_stats.rb
229
+ - lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb
209
230
  - lib/ehbrs_ruby_utils/bga/session/table.rb
210
231
  - lib/ehbrs_ruby_utils/bga/table.rb
211
232
  - lib/ehbrs_ruby_utils/bga/table/option.rb
212
233
  - lib/ehbrs_ruby_utils/bga/table/player.rb
234
+ - lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb
235
+ - lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_option.rb
236
+ - lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_player.rb
213
237
  - lib/ehbrs_ruby_utils/bga/urls.rb
214
238
  - lib/ehbrs_ruby_utils/circular_list_spreader.rb
215
239
  - lib/ehbrs_ruby_utils/circular_list_spreader/base_level.rb