fbtok 0.3.3 → 0.4.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.
data/lib/fbtok/opts.rb DELETED
@@ -1,181 +0,0 @@
1
-
2
- module SportDb
3
- class Parser
4
-
5
-
6
- ###
7
- ## note - Opts Helpers for now nested inside Parser - keep here? why? why not?
8
- class Opts
9
-
10
- def self.debug=(value) @@debug = value; end
11
- def self.debug?() @@debug ||= false; end ## note: default is FALSE
12
-
13
-
14
- SEASON_RE = %r{ (?:
15
- \d{4}-\d{2}
16
- | \d{4} (?: --[a-z0-9_-]+ )? ## todo/fix - allow "extension" to 2024-25 too - why?
17
- )
18
- }x
19
- SEASON = SEASON_RE.source ## "inline" helper for embedding in other regexes - keep? why? why not?
20
-
21
-
22
- ## note: if pattern includes directory add here
23
- ## (otherwise move to more "generic" datafile) - why? why not?
24
- ## update - note include/allow dot (.) too
25
- ## BUT NOT as first character!!! (e.g. exclude .confg.txt !!!)
26
- ## e.g. 2024-25/at.1.txt
27
- ## change to at_1 or uefa_cl or such - why? why not?
28
- MATCH_RE = %r{ (?: ## "classic" variant i) with season folder
29
- (?: ^|/ ) # beginning (^) or beginning of path (/)
30
- #{SEASON}
31
- /
32
- [a-z0-9][a-z0-9_.-]*\.txt$ ## txt e.g /1-premierleague.txt
33
- )
34
- |
35
- (?: ## "compact" variant ii) with season in filename
36
- (?: ^|/ ) # beginning (^) or beginning of path (/)
37
- (?: \d{4}-\d{2}
38
- |
39
- \d{4}
40
- )
41
- _ ## allow more than one underscore - why? why not?
42
- [a-z0-9][a-z0-9_.-]*\.txt$
43
- )
44
- }x
45
-
46
- ### add support for matchdatafile with season NOT in directory
47
- ## but starting filename e.g. 2024_friendlies.txt or 2024-25_bundesliga.txt
48
-
49
-
50
- def self._find( path )
51
- ## check - rename dir
52
- ## use root_dir or work_dir or cd or such - why? why not?
53
-
54
- datafiles = []
55
-
56
- ## note: normalize path - use File.expand_path ??
57
- ## change all backslash to slash for now
58
- ## path = path.gsub( "\\", '/' )
59
- path = File.expand_path( path )
60
-
61
-
62
- ## check all txt files
63
- ## note: incl. files starting with dot (.)) as candidates
64
- ## (normally excluded with just *)
65
- candidates = Dir.glob( "#{path}/**/{*,.*}.txt" )
66
- ## pp candidates
67
- candidates.each do |candidate|
68
- datafiles << candidate if MATCH_RE.match( candidate )
69
- end
70
-
71
- ## pp datafiles
72
- datafiles
73
- end
74
-
75
-
76
- def self._expand( arg )
77
- ## check if directory
78
- if Dir.exist?( arg )
79
- datafiles = _find( arg )
80
- if debug?
81
- puts
82
- puts " found #{datafiles.size} match txt datafiles in #{arg}"
83
- pp datafiles
84
- end
85
- datafiles
86
- else ## assume it's a file
87
- ## make sure path exists; raise error if not
88
- if File.exist?( arg )
89
- [arg] ## note - always return an array - why? why not?
90
- else
91
- raise Errno::ENOENT, "No such file or directory - #{arg}"
92
- end
93
- end
94
- end
95
-
96
-
97
- def self.expand_args( args )
98
- paths = []
99
- args.each do |arg|
100
- paths += _expand( arg )
101
- end
102
- paths
103
- end
104
-
105
-
106
-
107
- ## todo/check - find a better name
108
- ## e.g. BatchItem or PackageDef or ???
109
- ##
110
- ## find a different name for rec for named value props?
111
- ## why? why not?
112
- PathspecNode = Struct.new( :paths, :rec )
113
-
114
- def self.build_pathspec( paths: )
115
- PathspecNode.new( paths: paths, rec: {} )
116
- end
117
-
118
- def self.read_pathspecs( src )
119
- specs = []
120
-
121
- recs = read_csv( src )
122
- pp recs if debug?
123
-
124
- ## note - make pathspecs relative to passed in file arg!!!
125
- basedir = File.dirname( src )
126
- recs.each do |rec|
127
- path = rec['path']
128
- fullpath = File.expand_path( path, basedir )
129
- ## make sure path exists; raise error if not
130
- paths = if Dir.exist?( fullpath )
131
- _find( fullpath )
132
- else
133
- raise Errno::ENOENT, "No such directory - #{fullpath})"
134
- end
135
-
136
- specs << PathspecNode.new( paths: paths, rec: rec )
137
- end
138
- specs
139
- end
140
- end # class Opts
141
-
142
-
143
- ##
144
- # BatchReport (a.k.a. PathspecsReport)
145
-
146
- class BatchReport
147
-
148
- def initialize( specs, title: )
149
- @specs = specs
150
- @title = title
151
- end
152
-
153
- def build
154
- buf = String.new
155
- buf << "# #{@title} - #{@specs.size} dataset(s)\n\n"
156
-
157
- @specs.each_with_index do |spec,i|
158
- paths = spec.paths
159
- rec = spec.rec
160
- errors = rec['errors']
161
-
162
- if errors.size > 0
163
- buf << "!! #{errors.size} ERROR(S) "
164
- else
165
- buf << " OK "
166
- end
167
- buf << "%-20s" % rec['path']
168
- buf << " - #{paths.size} datafile(s)"
169
- buf << "\n"
170
-
171
- if errors.size > 0
172
- buf << errors.pretty_inspect
173
- buf << "\n"
174
- end
175
- end
176
-
177
- buf
178
- end # method build
179
- end # class BatchReport
180
- end # class Parser
181
- end # module SportDb