sportdb-quick 0.5.3 → 0.8.0

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.
@@ -1,140 +1,137 @@
1
- #####
2
- ## quick match reader for datafiles with league outlines
3
1
 
4
- module SportDb
5
- class QuickMatchReader
2
+ module Fbtxt
3
+ class Document
4
+ include Debuggable
6
5
 
7
- def self.debug=(value) @@debug = value; end
8
- def self.debug?() @@debug ||= false; end ## note: default is FALSE
9
- def debug?() self.class.debug?; end
10
6
 
7
+ def self.read( path )
8
+ ## note - use read_text from cocos - why? why not?
9
+ txt = read_text( path )
10
+ parse( txt )
11
+ end
11
12
 
13
+ def self.parse( txt )
14
+ new( txt )
15
+ end
12
16
 
13
- def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
14
- txt = File.open( path, 'r:utf-8' ) {|f| f.read }
15
- parse( txt )
16
- end
17
17
 
18
- def self.parse( txt )
19
- new( txt ).parse
20
- end
21
18
 
22
19
 
23
- include Logging
20
+ attr_reader :title ## e.g. league name (England | Premier League 2026/27) or such
21
+ attr_reader :matches
24
22
 
25
- def initialize( txt )
26
- @errors = []
27
- @outline = QuickLeagueOutline.parse( txt )
28
- end
23
+ attr_reader :teams
24
+ attr_reader :groups
25
+ attr_reader :rounds
29
26
 
30
27
  attr_reader :errors
31
28
  def errors?() @errors.size > 0; end
32
29
 
33
-
34
- ###
35
- # helpers get matches & more after parse; all stored in data
36
- #
37
- ## change/rename to event - why? why not?
38
- def league_name
39
- league = @data.keys[0]
40
- season = @data[ league ].keys[0]
41
-
42
- "#{league} #{season}"
30
+ ##
31
+ ## keep/store a reference to (source) txt - why? why not?
32
+ def initialize( txt, start: nil )
33
+ _parse( txt, start: start )
43
34
  end
44
35
 
45
- def matches
46
- league = @data.keys[0]
47
- season = @data[ league ].keys[0]
48
- @data[league][season]
49
- end
50
36
 
51
37
 
38
+ ## try to find season in heading
39
+ ## e.g. Österr. Bundesliga 2015/16 or 2015-16
40
+ ## World Cup 2018 or 2018 World Cup etc.
41
+ SEASON_IN_HEADING_RE = %r{
42
+ \b
43
+ (?<season>
44
+ \d{4}
45
+ (?: [\/-]
46
+ \d{1,4} )? ## optional 2nd year in season
47
+ )
48
+ \b
49
+ }x
52
50
 
53
- def parse
51
+
52
+ def _parse( txt, start: nil )
54
53
  ## note: every (new) read call - resets errors list to empty
55
- @errors = []
54
+ @title = nil ## or use '? or use '' - why? why not?
55
+ @matches = []
56
56
 
57
- @data = {} # return data hash with leagues
58
- # and seasons
59
- # for now merge stage into matches
57
+ @teams = []
58
+ @groups = []
59
+ @rounds = []
60
60
 
61
- @outline.each_sec do |sec| ## sec(tion)s
62
- ### move season parse into outline upstream - why? why not?
63
- season = Season.parse( sec.season ) ## convert (str) to season obj!!!
64
- league = sec.league
65
- stage = sec.stage
66
- lines = sec.lines
61
+ @errors = []
67
62
 
68
- start = if season.year?
69
- Date.new( season.start_year, 1, 1 )
70
- else
71
- Date.new( season.start_year, 7, 1 )
72
- end
73
63
 
74
- # if debug?
75
- # puts " (sec) lines:"
76
- # pp lines
77
- # end
64
+ parser = SportDb::Parser.new( txt ) ## use own parser instance (not shared) - why? why not?
65
+ tree, errors = parser.parse_with_errors
78
66
 
79
- ### note - skip section if no lines !!!!!
80
- next if lines.empty? ## or use lines.size == 0
67
+ @errors = errors
81
68
 
69
+ ## note - source file MUST always start with heading 1 for now
82
70
 
83
- parser = MatchParser.new( lines,
84
- start ) ## note: keep season start_at date for now (no need for more specific stage date need for now)
71
+ ##
72
+ ## !! (QUICK) PARSE ERROR - source MUST start with Heading1; got 34 nodes:
73
+ ## [<BlankLine>,
74
+ ## <BlankLine>,
75
+ ## <Heading1 World Cup 1930>,
85
76
 
86
- auto_conf_teams, matches, rounds, groups = parser.parse
77
+ ## remove leading BlankLines if any!!
78
+ while tree[0].is_a? RaccMatchParser::BlankLine
79
+ tree.shift ## remove (leading) blank line from parse tree
80
+ end
87
81
 
88
- ## auto-add "upstream" errors from parser
89
- @errors += parser.errors if parser.errors?
90
82
 
83
+ ## try to get league and season
84
+ if tree[0].is_a? RaccMatchParser::Heading1
85
+ @title = tree[0].text
86
+
87
+ if (m = SEASON_IN_HEADING_RE.match( @title ))
88
+ season = Season.parse( m[:season] ) ## convert (str) to season obj!!!
89
+ start = if season.year?
90
+ Date.new( season.start_year, 1, 1 )
91
+ else
92
+ Date.new( season.start_year, 7, 1 )
93
+ end
94
+ else
95
+ puts "!! (DOCUMENT) WARN - no season found in Heading1 >#{@title}<"
96
+ end
97
+ else
98
+ ### report error - source MUST start with heading 1
99
+ puts "!! (DOCUMENT) WARN - source SHOULD start with Heading1; got #{tree.size} nodes:"
100
+ pp tree
101
+ end
91
102
 
92
- if debug?
93
- puts ">>> #{auto_conf_teams.size} teams:"
94
- pp auto_conf_teams
95
- puts ">>> #{matches.size} matches:"
96
- ## pp matches
97
- puts ">>> #{rounds.size} rounds:"
98
- pp rounds
99
- puts ">>> #{groups.size} groups:"
100
- pp groups
101
- end
102
103
 
103
- ## note: pass along stage (if present): stage - optional from heading!!!!
104
- if stage
105
- matches.each do |match|
106
- match = match.update( stage: stage )
107
- end
108
- end
109
104
 
110
- @data[ league ] ||= {}
111
- @data[ league ][ season.key ] ||= []
105
+ ############
106
+ ### "walk" tree to get structs (matches/teams/etc.)
107
+ conv = SportDb::MatchTree.new( tree, start: start )
112
108
 
113
- @data[ league ][ season.key ] += matches
114
- ## note - skip teams, rounds, and groups for now
115
- end
109
+ teams, matches, rounds, groups = conv.convert
116
110
 
117
- ## check - only one league and one season
118
- ## allowed in quick style
119
111
 
112
+ ## auto-add "upstream" errors from parser
113
+ ## @errors += parser.errors if parser.errors?
120
114
 
121
- leagues = @data.keys
122
- if leagues.size != 1
123
- puts "!! (QUICK) PARSE ERROR - expected one league only; got #{leagues.size}:"
124
- pp leagues
125
- exit 1
126
- end
115
+ if debug?
116
+ puts ">>> #{teams.size} teams:"
117
+ pp teams
118
+ puts ">>> #{groups.size} groups:"
119
+ pp groups
120
+ puts ">>> #{rounds.size} rounds:"
121
+ pp rounds
122
+ puts ">>> #{matches.size} matches:"
123
+ ## pp matches
124
+ end
127
125
 
128
- seasons = @data[ leagues[0] ].keys
129
- if seasons.size != 1
130
- puts "!! (QUICK) PARSE ERROR - expected one #{leagues[0]} season only; got #{seasons.size}:"
131
- pp seasons
132
- exit 1
133
- end
134
126
 
135
- @data[ leagues[0] ][ seasons[0] ]
136
- end # method parse
127
+ @matches = matches
128
+
129
+ @teams = teams
130
+ @groups = groups
131
+ @rounds = rounds
137
132
 
138
- end # class QuickMatchReader
139
- end # module SportDb
133
+ self
134
+ end # method _parse
140
135
 
136
+ end # class Document
137
+ end # module Fbtxt
@@ -3,8 +3,8 @@ module SportDb
3
3
  module Module
4
4
  module Quick
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 5
7
- PATCH = 3
6
+ MINOR = 8
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
data/lib/sportdb/quick.rb CHANGED
@@ -1,37 +1,33 @@
1
- require 'sportdb/structs' # deps: score-foramts
2
- # season-formats
3
- # alphabets
4
- require 'sportdb/parser' # deps: cocos
5
- # season-formats
1
+ require 'sportdb/parser' # deps: cocos, racc
6
2
 
3
+ require 'season-formats'
7
4
 
8
5
 
9
- require 'logutils'
10
- module SportDb
11
- ## logging machinery shortcut; use LogUtils for now
12
- Logging = LogUtils::Logging
13
- end
14
6
 
15
7
 
16
8
 
17
9
  ## our own code
18
10
  require_relative 'quick/version'
19
11
 
20
- ## "generic" outline readers, documents & more
21
- ##
22
- ## todo/check - move outline reader upstream to cocos - why? why not?
23
- ## use read_outline(), parse_outline() - why? why not?
24
- require_relative 'quick/outline_reader'
25
- require_relative 'quick/outline'
26
-
27
12
  ## match & league machinery
28
- require_relative 'quick/match_parser'
13
+ require_relative 'quick/match_tree'
14
+ require_relative 'quick/match_tree-helpers'
29
15
 
30
- require_relative 'quick/quick_league_outline'
31
- require_relative 'quick/quick_match_reader'
16
+ require_relative 'quick/match_tree/match' ## ("inline") structs
17
+ require_relative 'quick/match_tree/goal'
18
+ require_relative 'quick/match_tree/round'
19
+ require_relative 'quick/match_tree/group'
32
20
 
21
+ require_relative 'quick/match_tree_on/on_group_def'
22
+ require_relative 'quick/match_tree_on/on_round_def'
23
+ require_relative 'quick/match_tree_on/on_round_outline'
24
+ require_relative 'quick/match_tree_on/on_date_header'
25
+ require_relative 'quick/match_tree_on/on_match_line'
26
+ require_relative 'quick/match_tree_on/on_goal_line'
33
27
 
34
28
 
35
- puts SportDb::Module::Quick.banner # say hello
29
+ require_relative 'quick/quick_match_reader'
30
+
36
31
 
37
32
 
33
+ puts SportDb::Module::Quick.banner # say hello
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-quick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-24 00:00:00.000000000 Z
11
+ date: 2026-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-parser
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.4
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.4
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: sportdb-structs
28
+ name: season-formats
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: 0.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0
41
- - !ruby/object:Gem::Dependency
42
- name: logutils
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 0.6.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 0.6.1
40
+ version: 0.1.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rdoc
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,10 +86,18 @@ files:
100
86
  - README.md
101
87
  - Rakefile
102
88
  - lib/sportdb/quick.rb
103
- - lib/sportdb/quick/match_parser.rb
104
- - lib/sportdb/quick/outline.rb
105
- - lib/sportdb/quick/outline_reader.rb
106
- - lib/sportdb/quick/quick_league_outline.rb
89
+ - lib/sportdb/quick/match_tree-helpers.rb
90
+ - lib/sportdb/quick/match_tree.rb
91
+ - lib/sportdb/quick/match_tree/goal.rb
92
+ - lib/sportdb/quick/match_tree/group.rb
93
+ - lib/sportdb/quick/match_tree/match.rb
94
+ - lib/sportdb/quick/match_tree/round.rb
95
+ - lib/sportdb/quick/match_tree_on/on_date_header.rb
96
+ - lib/sportdb/quick/match_tree_on/on_goal_line.rb
97
+ - lib/sportdb/quick/match_tree_on/on_group_def.rb
98
+ - lib/sportdb/quick/match_tree_on/on_match_line.rb
99
+ - lib/sportdb/quick/match_tree_on/on_round_def.rb
100
+ - lib/sportdb/quick/match_tree_on/on_round_outline.rb
107
101
  - lib/sportdb/quick/quick_match_reader.rb
108
102
  - lib/sportdb/quick/version.rb
109
103
  homepage: https://github.com/sportdb/sport.db