sutazekarate 0.0.5 → 0.0.7

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: 7b54c32b48b7aa22641911deb83bfe96e3ce781f67559b4c26d763a3713e3eb0
4
- data.tar.gz: 0affc3965a975e05e355690aa7dd43c835fa0dd5dccb69da1913e5d353c46ac0
3
+ metadata.gz: 4fe3b7751ee725981c6ca1c168f2d1453d1af0ed9732c891ad5c29a37a2b9766
4
+ data.tar.gz: 3c97f7ac6de44a2835938f66823dc7631fc1a308000205977fd634d6d28e065e
5
5
  SHA512:
6
- metadata.gz: 82154f725706f961e15710b77068dcaa9e4b8a38b1250a48682451162d1c516aa2f112869d8f8550aece11c8c24885d98e9332efde309225cde92f8ec7296694
7
- data.tar.gz: 4bcd5ee5a40d264a56630d728fcc3b537e2ad566c24309f023291172c6922389026dd0e297739f5af2c58c25d17e8b4d889435d22396d43cba994eec6e4bbe70
6
+ metadata.gz: 39b5978a5036822560c1bf91b9cbf1f940b8681bfb0dd2d4dc31035f9a8e5c243566df1e9c18ff933761010412d99bca16fa90f7cff18d40825343eefaa7bc33
7
+ data.tar.gz: 11b94fea3be8b6ff9197700f88307f5f56651b57c63195f968f348d5bd00500b8a6ab6a24ad180fbd739ebbeb5e62c7dd4c7d42a23e2127f581f1f2fde7ce09a
@@ -11,6 +11,7 @@ module Sutazekarate
11
11
  attribute :position
12
12
  attribute :name
13
13
  attribute :discipline
14
+ attribute :duration
14
15
  attribute :location
15
16
  attribute :location_color
16
17
  attribute :time_range
@@ -114,7 +115,10 @@ module Sutazekarate
114
115
  id = Addressable::URI.parse(detail_element.search('a').first.attr('href')).query_values['k']
115
116
  category_element = Nokogiri::HTML5.fragment(data['kategoria'])
116
117
  category_span_elements = category_element.search('span')
117
- name = category_span_elements[0].text.strip
118
+ name_raw = category_span_elements[0].text.strip
119
+ name_match = name_raw.match(/^([^(\/]+?)\s*(?:\(([^)]+)\))?\s*(?:\/([^\/]+)\/)?$/)
120
+ name = name_match[1]
121
+ duration = name_match[3]
118
122
  detail_element = category_span_elements[1]
119
123
  location = nil
120
124
  location_color = nil
@@ -133,6 +137,7 @@ module Sutazekarate
133
137
  position: data['pc'],
134
138
  name:,
135
139
  discipline:,
140
+ duration:,
136
141
  location:,
137
142
  location_color:,
138
143
  time_range:,
@@ -44,27 +44,15 @@ module Sutazekarate
44
44
 
45
45
  def timetables
46
46
  @timetables ||= begin
47
- categories
48
- .group_by(&:location)
49
- .map do |location, location_categories|
50
- entries = location_categories
51
- .select { |category| category.time_range.present? }
52
- .sort_by { |category| category.time_range.begin }
53
- .map do |location_category|
54
- TimetableEntry.new(
55
- category: location_category,
56
- time_range: location_category.time_range,
57
- )
58
- end
47
+ logger.debug("Fetching timetable for competition #{id}")
48
+ response = HTTP.get("https://sutazekarate.sk/pdf_timetable3.php?sutaz=#{id}")
59
49
 
60
- Timetable.new(
61
- location:,
62
- entries:,
63
- )
50
+ html = Nokogiri::HTML5.fragment(response.body.to_s)
51
+
52
+ html.search('.divttm').map do |location_element|
53
+ Timetable.build(location_element, categories:)
64
54
  end
65
55
  end
66
- rescue => ex
67
- binding.irb
68
56
  end
69
57
 
70
58
  def self.all(year: Date.today.year)
@@ -6,5 +6,18 @@ module Sutazekarate
6
6
 
7
7
  attribute :location
8
8
  attribute :entries
9
+
10
+ def self.build(location_element, categories: [])
11
+ location = location_element.search('.hlavicka').text.strip
12
+
13
+ entries = location_element.search('ul li').map do |entry_element|
14
+ TimetableEntry.build(entry_element, categories:)
15
+ end
16
+
17
+ Timetable.new(
18
+ location:,
19
+ entries:,
20
+ )
21
+ end
9
22
  end
10
23
  end
@@ -4,6 +4,7 @@ module Sutazekarate
4
4
  include ActiveModel::Attributes
5
5
  include ActiveModel::Serializers::JSON
6
6
 
7
+ attribute :title
7
8
  attribute :category
8
9
  attribute :time_range
9
10
 
@@ -18,5 +19,22 @@ module Sutazekarate
18
19
  def time_end
19
20
  time_range.end
20
21
  end
22
+
23
+ def self.build(entry_element, categories: [])
24
+ title = entry_element.children.first.text.strip
25
+ time_range_raw = entry_element.children.last.text.strip
26
+ time_range_match = time_range_raw.match(/(\d+:\d+) - (\d+:\d+)/)
27
+ time_range = Time.zone.parse(time_range_match[1])..Time.zone.parse(time_range_match[2])
28
+
29
+ category = categories.find do |category|
30
+ category.name == title
31
+ end
32
+
33
+ TimetableEntry.new(
34
+ category:,
35
+ title:,
36
+ time_range:,
37
+ )
38
+ end
21
39
  end
22
40
  end
@@ -1,3 +1,3 @@
1
1
  module Sutazekarate
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
data/lib/sutazekarate.rb CHANGED
@@ -4,7 +4,9 @@ require 'active_model'
4
4
  require 'http'
5
5
  require 'nokogiri'
6
6
 
7
- Time.zone_default = Time.find_zone!(ENV.fetch('TZ', 'Europe/Bratislava'))
7
+ unless Time.zone
8
+ Time.zone_default = Time.find_zone!(ENV.fetch('TZ', 'Europe/Bratislava'))
9
+ end
8
10
 
9
11
  loader = Zeitwerk::Loader.for_gem
10
12
  loader.setup
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.5
4
+ version: 0.0.7
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: 2024-09-12 00:00:00.000000000 Z
11
+ date: 2024-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http