ehbrs_ruby_utils 0.23.0 → 0.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs_ruby_utils/bga/parsers/game_stats/players.rb +2 -2
- data/lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb +4 -2
- data/lib/ehbrs_ruby_utils/bga/parsers/table/players.rb +1 -1
- data/lib/ehbrs_ruby_utils/bga/parsers/table.rb +8 -0
- data/lib/ehbrs_ruby_utils/bga/session/login.rb +1 -1
- data/lib/ehbrs_ruby_utils/bga/session/player_tables_on_game_stats.rb +99 -0
- data/lib/ehbrs_ruby_utils/bga/session.rb +10 -5
- data/lib/ehbrs_ruby_utils/bga/table.rb +5 -0
- data/lib/ehbrs_ruby_utils/bga/urls.rb +7 -1
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml +10 -10
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.source.html +1083 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.target.yaml +1127 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html +1497 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml +47 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml +1 -0
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef922dc8e609ca372c63e29cbfda768e95abc03b24c0fd5b9a5c6d46bf707445
|
4
|
+
data.tar.gz: ad3022d2b588614b4471798f751a8edca0800e301ab0f7bd689a22fc684fd59f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2e2052b2490544bcb9edd3234d082f46489aa76d277889d33cc75ad75e31e9181c1c38deb00b4741723ba396be7c0f2ebbe71931845fd7db4145cfffe60dd00
|
7
|
+
data.tar.gz: 4b27d92bade1d8a85151dbd2ce9c101286b75c433327a849fbab1bb275ce47e4c6b06c850616b320480b18ea294b59c76b55199023e80bcb38c7da465d4c54c1
|
@@ -10,10 +10,10 @@ module EhbrsRubyUtils
|
|
10
10
|
class Players < ::Aranha::Parsers::Html::ItemList
|
11
11
|
ITEMS_XPATH = '//div[@class = "simple-score-entry"]'
|
12
12
|
|
13
|
-
field :rank, :
|
13
|
+
field :rank, :integer_optional, './div[@class = "rank"]'
|
14
14
|
field :id, :integer, './div[@class = "name"]/a/@href'
|
15
15
|
field :name, :string, './div[@class = "name"]/a/text()'
|
16
|
-
field :score, :
|
16
|
+
field :score, :integer_optional, './div[@class = "score"]'
|
17
17
|
|
18
18
|
def items_xpath
|
19
19
|
ITEMS_XPATH
|
@@ -23,7 +23,7 @@ module EhbrsRubyUtils
|
|
23
23
|
|
24
24
|
def item_data(item)
|
25
25
|
r = super
|
26
|
-
r[:
|
26
|
+
r[:id] = table_name_to_id(r.delete(:table_name))
|
27
27
|
r[:players] = players_data(r.delete(:players))
|
28
28
|
r
|
29
29
|
end
|
@@ -36,8 +36,10 @@ module EhbrsRubyUtils
|
|
36
36
|
).data
|
37
37
|
end
|
38
38
|
|
39
|
+
# @param name [String]
|
40
|
+
# @return [Integer]
|
39
41
|
def table_name_to_id(name)
|
40
|
-
name.gsub(/\A\#/, '')
|
42
|
+
name.gsub(/\A\#/, '').to_i
|
41
43
|
end
|
42
44
|
|
43
45
|
require_sub __FILE__
|
@@ -14,7 +14,7 @@ module EhbrsRubyUtils
|
|
14
14
|
field :table_rank, :integer, './div[@class = "rank"]'
|
15
15
|
field :id, :integer, './div[@class = "name"]/a/@href'
|
16
16
|
field :name, :string, './div[@class = "name"]/a/text()'
|
17
|
-
field :score, :
|
17
|
+
field :score, :integer_optional, './div[@class = "score"]'
|
18
18
|
field :win_points, :string, './/*[starts-with(@id, "winpoints_value_")]/text()'
|
19
19
|
field :game_rank, :integer, './/*[@class = "gamerank_value"]/text()'
|
20
20
|
|
@@ -14,6 +14,7 @@ module EhbrsRubyUtils
|
|
14
14
|
field :estimated_duration, :string, './/*[@id = "estimated_duration"]/text()'
|
15
15
|
field :options, :node, './/*[@id = "gameoptions"]'
|
16
16
|
field :players, :node, './/*[@id = "game_result"]'
|
17
|
+
field :game_conceded, :node, './/*[@id = "game_conceded" and @style="display: block;"]'
|
17
18
|
|
18
19
|
def item_xpath
|
19
20
|
ITEM_XPATH
|
@@ -25,6 +26,7 @@ module EhbrsRubyUtils
|
|
25
26
|
r[key] = self.class.const_get(key.to_s.camelize).from_node(r.fetch(key)).data
|
26
27
|
end
|
27
28
|
r[:creation_time] = process_creation_time(r[:creation_time])
|
29
|
+
r[:game_conceded] = process_game_conceded(r[:game_conceded])
|
28
30
|
r
|
29
31
|
end
|
30
32
|
|
@@ -34,6 +36,12 @@ module EhbrsRubyUtils
|
|
34
36
|
creation_time.gsub('Criado:', '').strip
|
35
37
|
end
|
36
38
|
|
39
|
+
# @param node [Nokogiri::XML::Element]
|
40
|
+
# @return [Boolean]
|
41
|
+
def process_game_conceded(node)
|
42
|
+
node.present?
|
43
|
+
end
|
44
|
+
|
37
45
|
require_sub __FILE__
|
38
46
|
end
|
39
47
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/bga/parsers/table'
|
4
|
+
require 'ehbrs_ruby_utils/bga/table'
|
5
|
+
require 'ehbrs_ruby_utils/bga/urls'
|
6
|
+
require 'eac_ruby_utils/core_ext'
|
7
|
+
|
8
|
+
module EhbrsRubyUtils
|
9
|
+
module Bga
|
10
|
+
class Session < ::SimpleDelegator
|
11
|
+
class PlayerTablesOnGameStats
|
12
|
+
include ::EhbrsRubyUtils::Bga::Urls
|
13
|
+
enable_method_class
|
14
|
+
enable_simple_cache
|
15
|
+
common_constructor :session, :player_id, :until_table_id, default: [nil] do
|
16
|
+
self.until_table_id = until_table_id.if_present(&:to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
SEE_MORE_BUTTON_ID = 'see_more_tables'
|
20
|
+
|
21
|
+
def result
|
22
|
+
navigate_to_page
|
23
|
+
loop do
|
24
|
+
return result_data unless more?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Addressable::URI]
|
29
|
+
def url
|
30
|
+
player_game_stats_url(player_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Array<Hash>]
|
36
|
+
def current_data_uncached
|
37
|
+
::EhbrsRubyUtils::Bga::Parsers::GameStats.from_content(session.current_source).data
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Array<Hash>]
|
41
|
+
def new_current_data
|
42
|
+
reset_cache(:current_data)
|
43
|
+
current_data
|
44
|
+
end
|
45
|
+
|
46
|
+
def navigate_to_page
|
47
|
+
session.navigate.to url
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Boolean]
|
51
|
+
def more?
|
52
|
+
!(table_id_found? || list_end_reached?)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean]
|
56
|
+
def list_end_reached?
|
57
|
+
previous_count = current_data.count
|
58
|
+
result = nil
|
59
|
+
session.wait_for_click(id: SEE_MORE_BUTTON_ID)
|
60
|
+
session.wait.until do
|
61
|
+
result = list_end_reached_non_waiting(previous_count)
|
62
|
+
!result.nil?
|
63
|
+
end
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param previous_count [Integer]
|
68
|
+
# @return [Boolean, nil]
|
69
|
+
def list_end_reached_non_waiting(previous_count)
|
70
|
+
if session.message_info.present?
|
71
|
+
true
|
72
|
+
elsif new_current_data.count != previous_count
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Array<Hash>]
|
78
|
+
def result_data
|
79
|
+
until_table_id.if_present(current_data) do |v|
|
80
|
+
r = []
|
81
|
+
current_data.each do |d|
|
82
|
+
break if d.fetch(:id) == v
|
83
|
+
|
84
|
+
r << d
|
85
|
+
end
|
86
|
+
r
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Boolean]
|
91
|
+
def table_id_found?
|
92
|
+
until_table_id.if_present(false) do |v|
|
93
|
+
current_data.any? { |d| d.fetch(:id) == v }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -12,16 +12,21 @@ module EhbrsRubyUtils
|
|
12
12
|
|
13
13
|
common_constructor :username, :password, super_args: -> { [::Aranha::Selenium::Session.new] }
|
14
14
|
|
15
|
-
# @return [String]
|
16
|
-
def message_info
|
17
|
-
wait_for_click(id: MESSAGE_ID).text
|
18
|
-
end
|
19
|
-
|
20
15
|
# @return [EhbrsRubyUtils::Bga::Session::Player]
|
21
16
|
def player(id)
|
22
17
|
::EhbrsRubyUtils::Bga::Session::Player.new(self, id)
|
23
18
|
end
|
24
19
|
|
20
|
+
# @return [String, nil]
|
21
|
+
def message_info
|
22
|
+
find_or_not_element(id: MESSAGE_ID).if_present { |v| v.text.strip }
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def waited_message_info
|
27
|
+
wait_for_click(id: MESSAGE_ID).text
|
28
|
+
end
|
29
|
+
|
25
30
|
require_sub __FILE__, include_modules: true, require_mode: :kernel
|
26
31
|
end
|
27
32
|
end
|
@@ -9,7 +9,7 @@ module EhbrsRubyUtils
|
|
9
9
|
common_concern
|
10
10
|
|
11
11
|
module InstanceMethods
|
12
|
-
ROOT_URL = 'https://
|
12
|
+
ROOT_URL = 'https://boardgamearena.com'
|
13
13
|
|
14
14
|
# @param suffix [String]
|
15
15
|
# @return [Addressable::URI]
|
@@ -17,6 +17,12 @@ module EhbrsRubyUtils
|
|
17
17
|
root_url + suffix
|
18
18
|
end
|
19
19
|
|
20
|
+
# @para player_id [Integer]
|
21
|
+
# @return [Addressable::URI]
|
22
|
+
def player_game_stats_url(player_id)
|
23
|
+
build_url("/gamestats?player=#{player_id}")
|
24
|
+
end
|
25
|
+
|
20
26
|
# @return [Addressable::URI]
|
21
27
|
def root_url
|
22
28
|
ROOT_URL.to_uri
|
@@ -4,7 +4,7 @@
|
|
4
4
|
:leave_penalty:
|
5
5
|
:rank_increment:
|
6
6
|
:rank_after: 254
|
7
|
-
:
|
7
|
+
:id: 374270557
|
8
8
|
:players:
|
9
9
|
- :rank: 1
|
10
10
|
:id: 92442373
|
@@ -19,7 +19,7 @@
|
|
19
19
|
:leave_penalty:
|
20
20
|
:rank_increment:
|
21
21
|
:rank_after: 122
|
22
|
-
:
|
22
|
+
:id: 375280703
|
23
23
|
:players:
|
24
24
|
- :rank: 1
|
25
25
|
:id: 84920871
|
@@ -34,7 +34,7 @@
|
|
34
34
|
:leave_penalty:
|
35
35
|
:rank_increment:
|
36
36
|
:rank_after: 106
|
37
|
-
:
|
37
|
+
:id: 373870907
|
38
38
|
:players:
|
39
39
|
- :rank: 1
|
40
40
|
:id: 84920871
|
@@ -49,7 +49,7 @@
|
|
49
49
|
:leave_penalty:
|
50
50
|
:rank_increment:
|
51
51
|
:rank_after: 105
|
52
|
-
:
|
52
|
+
:id: 373602409
|
53
53
|
:players:
|
54
54
|
- :rank: 1
|
55
55
|
:id: 84920871
|
@@ -64,7 +64,7 @@
|
|
64
64
|
:leave_penalty:
|
65
65
|
:rank_increment:
|
66
66
|
:rank_after: 83
|
67
|
-
:
|
67
|
+
:id: 372806271
|
68
68
|
:players:
|
69
69
|
- :rank: 1
|
70
70
|
:id: 84920871
|
@@ -79,7 +79,7 @@
|
|
79
79
|
:leave_penalty:
|
80
80
|
:rank_increment:
|
81
81
|
:rank_after: 1
|
82
|
-
:
|
82
|
+
:id: 373870075
|
83
83
|
:players:
|
84
84
|
- :rank: 1
|
85
85
|
:id: 90379834
|
@@ -94,7 +94,7 @@
|
|
94
94
|
:leave_penalty:
|
95
95
|
:rank_increment:
|
96
96
|
:rank_after: 268
|
97
|
-
:
|
97
|
+
:id: 370752197
|
98
98
|
:players:
|
99
99
|
- :rank: 1
|
100
100
|
:id: 84920871
|
@@ -109,7 +109,7 @@
|
|
109
109
|
:leave_penalty:
|
110
110
|
:rank_increment:
|
111
111
|
:rank_after: 262
|
112
|
-
:
|
112
|
+
:id: 372466754
|
113
113
|
:players:
|
114
114
|
- :rank: 1
|
115
115
|
:id: 84920871
|
@@ -124,7 +124,7 @@
|
|
124
124
|
:leave_penalty:
|
125
125
|
:rank_increment:
|
126
126
|
:rank_after: 100
|
127
|
-
:
|
127
|
+
:id: 373747455
|
128
128
|
:players:
|
129
129
|
- :rank: 1
|
130
130
|
:id: 84559362
|
@@ -139,7 +139,7 @@
|
|
139
139
|
:leave_penalty:
|
140
140
|
:rank_increment:
|
141
141
|
:rank_after: 256
|
142
|
-
:
|
142
|
+
:id: 373436042
|
143
143
|
:players:
|
144
144
|
- :rank: 1
|
145
145
|
:id: 84920871
|