sutazekarate 0.0.11 → 0.0.13

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: ec0f9f743ae630e79475e2f4274e6624a5104131ffef05297b4ccb02eb89345a
4
+ data.tar.gz: 1104cbb6defe911b214491a357c30cd752bb8f30bc131d65c2193e471c90ecd7
5
5
  SHA512:
6
- metadata.gz: 188676dca6c78d765ca754a0520f7371f4bab32a2ed9413dd431d14c931a3e2ff8ea87a6f2cbc751573b37fffad343a9ad2ea9c4c248e9dc9129b26e7bde8b78
7
- data.tar.gz: 3aba9d16de529537c4b8aa00db065fa84665849fa0f473296c2a5bf85399d0186175e30706779c5940fa111146b2ccc44f9bc217ab965a29454dcce4320ac27f
6
+ metadata.gz: a7340631e55b884dd85b06b86755220a565df0880f7d0f66ddaeb6befd9760c1677123cc1abc436f19ab4f04e359aee950ebd50281d08c5777c501cbeb4a2e2b
7
+ data.tar.gz: '084e29ab431be9e0c3b1f8363122be60ec900040c803e9b60e5a7f110b2f0cac72b36482bb18065bf57d6d16773706f9d014d64c44b19ee443ba2395b8f934ae'
@@ -17,6 +17,10 @@ module Sutazekarate
17
17
  attribute :location_color
18
18
  attribute :time_range
19
19
 
20
+ attribute :has_draw_flat
21
+ attribute :has_draw_ladder
22
+ attribute :has_results_ladder
23
+
20
24
  def serializable_hash(options = nil)
21
25
  super.merge(time_begin:, time_end:).except('time_range')
22
26
  end
@@ -41,62 +45,32 @@ module Sutazekarate
41
45
  end
42
46
 
43
47
  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
48
+ draw_ladder
49
+ end
73
50
 
74
- Competitor.new(
75
- id: id,
76
- name: name,
77
- club: Club.new(name: club),
78
- )
79
- end
51
+ def draw_ladder_url
52
+ "https://www.sutazekarate.sk/sutaze_kategoriarozl.php?k=#{id}"
53
+ end
80
54
 
81
- Pair.new(
82
- index: pair_index,
83
- competitor1: competitors[0],
84
- competitor2: competitors[1],
85
- )
86
- end
55
+ def draw_ladder_export_url
56
+ "https://www.sutazekarate.sk/pdf_rozlosovanieexport.php?id=#{id}"
57
+ end
87
58
 
88
- stages << Stage.new(
89
- index: stage_index,
90
- pairs:,
91
- )
59
+ def draw_ladder
60
+ @draw_ladder ||= begin
61
+ logger.debug("Fetching draw ladder for category #{id}")
62
+ parse_ladder(draw_ladder_url)
63
+ end
64
+ end
92
65
 
93
- stage_index += 1
94
- end
66
+ def results_ladder_url
67
+ "https://www.sutazekarate.sk/sutaze_kategoriarec.php?k=#{id}"
68
+ end
95
69
 
96
- Ladder.new(
97
- export_url:,
98
- stages:,
99
- )
70
+ def results_ladder
71
+ @results_ladder ||= begin
72
+ logger.debug("Fetching results ladder for category #{id}")
73
+ parse_ladder(results_ladder_url)
100
74
  end
101
75
  end
102
76
 
@@ -111,6 +85,22 @@ module Sutazekarate
111
85
  preload.map(&:value)
112
86
  end
113
87
 
88
+ def self.find(id)
89
+ response = HTTP.get("https://www.sutazekarate.sk/sutaze_kategoriazoz.php?k=#{id}")
90
+ html = Nokogiri::HTML5.fragment(response.body.to_s)
91
+
92
+ competition_link = html.search('a').find do |x|
93
+ x.attr('href').starts_with?('sutaze_sutazinf.php')
94
+ end
95
+ competition_href = competition_link.attr('href')
96
+
97
+ competition_id = Addressable::URI.parse(competition_href).query_values['sutaz']
98
+
99
+ Competition.find(competition_id).categories.find do |category|
100
+ category.id.to_s == id.to_s
101
+ end
102
+ end
103
+
114
104
  def self.build(data)
115
105
  detail_element = Nokogiri::HTML5.fragment(data['detail'])
116
106
  id = Addressable::URI.parse(detail_element.search('a').first.attr('href')).query_values['k']
@@ -140,6 +130,21 @@ module Sutazekarate
140
130
  end
141
131
  discipline = Nokogiri::HTML5.fragment(data['disciplina']).text.strip
142
132
 
133
+ actions_element = Nokogiri::HTML5.fragment(data['detail'])
134
+ action_urls = actions_element.search('a').map do |a|
135
+ a.attr('href')
136
+ end
137
+
138
+ has_draw_flat = action_urls.any? do |url|
139
+ url.start_with?('pdf_rozlosovanieexportrobin.php')
140
+ end
141
+ has_draw_ladder = action_urls.any? do |url|
142
+ url.start_with?('sutaze_kategoriarozl.php')
143
+ end
144
+ has_results_ladder = action_urls.any? do |url|
145
+ url.start_with?('sutaze_kategoriarec.php')
146
+ end
147
+
143
148
  new(
144
149
  id:,
145
150
  position: data['pc'],
@@ -150,6 +155,72 @@ module Sutazekarate
150
155
  location:,
151
156
  location_color:,
152
157
  time_range:,
158
+ has_draw_flat:,
159
+ has_draw_ladder:,
160
+ has_results_ladder:,
161
+ )
162
+ end
163
+
164
+ private
165
+
166
+ def parse_ladder(url)
167
+ response = HTTP.get(url)
168
+ html = Nokogiri::HTML5(response.body.to_s)
169
+
170
+ pools = []
171
+ html.search('.pool').map do |pool|
172
+ title = pool.search('h5,h6').first.text.strip
173
+
174
+ stages = []
175
+
176
+ stage_index = 0
177
+ loop do
178
+ stage_element = html.search(".stlpecn.posun#{stage_index}").first
179
+ unless stage_element
180
+ break
181
+ end
182
+
183
+ pairs = stage_element.search('.obalao').map.with_index do |pair_element, pair_index|
184
+ competitors = pair_element.search('.okienkopavukR').map do |competitor_element|
185
+ id_element = competitor_element.search('#sutaziaci').first
186
+ unless id_element
187
+ next nil
188
+ end
189
+
190
+ id = competitor_element.search('#sutaziaci').first.attr('value')
191
+ name = competitor_element.search('.meno').text.strip
192
+ club = competitor_element.search('.klub').text.strip
193
+
194
+ Competitor.new(
195
+ id: id,
196
+ name: name,
197
+ club: Club.new(name: club),
198
+ )
199
+ end
200
+
201
+ Pair.new(
202
+ index: pair_index,
203
+ competitor1: competitors[0],
204
+ competitor2: competitors[1],
205
+ )
206
+ end
207
+
208
+ stages << Stage.new(
209
+ index: stage_index,
210
+ pairs:,
211
+ )
212
+
213
+ stage_index += 1
214
+ end
215
+
216
+ pools << Pool.new(
217
+ title:,
218
+ stages:,
219
+ )
220
+ end
221
+
222
+ Ladder.new(
223
+ pools:,
153
224
  )
154
225
  end
155
226
  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.13'.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.13
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