sutazekarate 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9affd5ab82a716e54b9e0d6eb78ae74c3898327e0d32949588dd36218a163e46
4
- data.tar.gz: baa04e8b11ad761622ae6dd004e5baffff30f3663deb2de5f80f2224f4e06d7c
3
+ metadata.gz: 1bdf26806118aeff69b17673329ef6fdd83c5cb0b7d7a8c35e77deea83b6add5
4
+ data.tar.gz: 7c84a9798b04fc02ebbd4682e2d72f9f868a8c222f6530861579384cf00f24d4
5
5
  SHA512:
6
- metadata.gz: 188676dca6c78d765ca754a0520f7371f4bab32a2ed9413dd431d14c931a3e2ff8ea87a6f2cbc751573b37fffad343a9ad2ea9c4c248e9dc9129b26e7bde8b78
7
- data.tar.gz: 3aba9d16de529537c4b8aa00db065fa84665849fa0f473296c2a5bf85399d0186175e30706779c5940fa111146b2ccc44f9bc217ab965a29454dcce4320ac27f
6
+ metadata.gz: b9d2397871ae1b390a0d8e320a20634af04378d6a9e45d50305bd59fca64c4662d13894b176fd2a4c917fa409382d51a725b93ca603e322c38251caea67fa4d1
7
+ data.tar.gz: 30838173feefaeaf8c1688c358caf1713966a9daa43ab10163f9883bbaea59330e20a5413d5b8f05cbb6de6c52ad1be83cbec58493c235216b3e1c45ef3096ec
@@ -41,62 +41,32 @@ module Sutazekarate
41
41
  end
42
42
 
43
43
  def ladder
44
- @ladder ||= begin
45
- logger.debug("Fetching ladder for category #{id}")
46
- response = HTTP.get("https://www.sutazekarate.sk/sutaze_kategoriarozl.php?k=#{id}")
47
- html = Nokogiri::HTML5(response.body.to_s)
48
-
49
- export_element = html.search('a').find do |elem|
50
- elem.attr('href').start_with?('pdf_rozlosovanieexport.php')
51
- end
52
- export_url = "https://www.sutazekarate.sk/#{export_element.attr('href')}"
53
-
54
- stages = []
55
-
56
- stage_index = 0
57
- loop do
58
- stage_element = html.search(".stlpecn.posun#{stage_index}").first
59
- unless stage_element
60
- break
61
- end
62
-
63
- pairs = stage_element.search('.obalao').map.with_index do |pair_element, pair_index|
64
- competitors = pair_element.search('.okienkopavukR').map do |competitor_element|
65
- id_element = competitor_element.search('#sutaziaci').first
66
- unless id_element
67
- next nil
68
- end
69
-
70
- id = competitor_element.search('#sutaziaci').first.attr('value')
71
- name = competitor_element.search('.meno').text.strip
72
- club = competitor_element.search('.klub').text.strip
44
+ draw_ladder
45
+ end
73
46
 
74
- Competitor.new(
75
- id: id,
76
- name: name,
77
- club: Club.new(name: club),
78
- )
79
- end
47
+ def draw_ladder_url
48
+ "https://www.sutazekarate.sk/sutaze_kategoriarozl.php?k=#{id}"
49
+ end
80
50
 
81
- Pair.new(
82
- index: pair_index,
83
- competitor1: competitors[0],
84
- competitor2: competitors[1],
85
- )
86
- end
51
+ def draw_ladder_export_url
52
+ "https://www.sutazekarate.sk/pdf_rozlosovanieexport.php?id=#{id}"
53
+ end
87
54
 
88
- stages << Stage.new(
89
- index: stage_index,
90
- pairs:,
91
- )
55
+ def draw_ladder
56
+ @draw_ladder ||= begin
57
+ logger.debug("Fetching draw ladder for category #{id}")
58
+ parse_ladder(draw_ladder_url)
59
+ end
60
+ end
92
61
 
93
- stage_index += 1
94
- end
62
+ def results_ladder_url
63
+ "https://www.sutazekarate.sk/sutaze_kategoriarec.php?k=#{id}"
64
+ end
95
65
 
96
- Ladder.new(
97
- export_url:,
98
- stages:,
99
- )
66
+ def results_ladder
67
+ @results_ladder ||= begin
68
+ logger.debug("Fetching results ladder for category #{id}")
69
+ parse_ladder(results_ladder_url)
100
70
  end
101
71
  end
102
72
 
@@ -152,5 +122,68 @@ module Sutazekarate
152
122
  time_range:,
153
123
  )
154
124
  end
125
+
126
+ private
127
+
128
+ def parse_ladder(url)
129
+ response = HTTP.get(url)
130
+ html = Nokogiri::HTML5(response.body.to_s)
131
+
132
+ pools = []
133
+ html.search('.pool').map do |pool|
134
+ title = pool.search('h5,h6').first.text.strip
135
+
136
+ stages = []
137
+
138
+ stage_index = 0
139
+ loop do
140
+ stage_element = html.search(".stlpecn.posun#{stage_index}").first
141
+ unless stage_element
142
+ break
143
+ end
144
+
145
+ pairs = stage_element.search('.obalao').map.with_index do |pair_element, pair_index|
146
+ competitors = pair_element.search('.okienkopavukR').map do |competitor_element|
147
+ id_element = competitor_element.search('#sutaziaci').first
148
+ unless id_element
149
+ next nil
150
+ end
151
+
152
+ id = competitor_element.search('#sutaziaci').first.attr('value')
153
+ name = competitor_element.search('.meno').text.strip
154
+ club = competitor_element.search('.klub').text.strip
155
+
156
+ Competitor.new(
157
+ id: id,
158
+ name: name,
159
+ club: Club.new(name: club),
160
+ )
161
+ end
162
+
163
+ Pair.new(
164
+ index: pair_index,
165
+ competitor1: competitors[0],
166
+ competitor2: competitors[1],
167
+ )
168
+ end
169
+
170
+ stages << Stage.new(
171
+ index: stage_index,
172
+ pairs:,
173
+ )
174
+
175
+ stage_index += 1
176
+ end
177
+
178
+ pools << Pool.new(
179
+ title:,
180
+ stages:,
181
+ )
182
+ end
183
+
184
+ Ladder.new(
185
+ pools:,
186
+ )
187
+ end
155
188
  end
156
189
  end
@@ -5,6 +5,6 @@ module Sutazekarate
5
5
  include ActiveModel::Serializers::JSON
6
6
 
7
7
  attribute :export_url
8
- attribute :stages
8
+ attribute :pools
9
9
  end
10
10
  end
@@ -0,0 +1,10 @@
1
+ module Sutazekarate
2
+ class Pool
3
+ include ActiveModel::Model
4
+ include ActiveModel::Attributes
5
+ include ActiveModel::Serializers::JSON
6
+
7
+ attribute :title
8
+ attribute :stages
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Sutazekarate
2
- VERSION = '0.0.11'.freeze
2
+ VERSION = '0.0.12'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sutazekarate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Al Hafoudh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-17 00:00:00.000000000 Z
11
+ date: 2025-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -125,6 +125,7 @@ files:
125
125
  - lib/sutazekarate/ladder.rb
126
126
  - lib/sutazekarate/logging.rb
127
127
  - lib/sutazekarate/pair.rb
128
+ - lib/sutazekarate/pool.rb
128
129
  - lib/sutazekarate/stage.rb
129
130
  - lib/sutazekarate/timetable.rb
130
131
  - lib/sutazekarate/timetable_entry.rb