fbtok 0.5.2 → 0.5.3

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: 9eef844f7c201c7ead0ccc9ed46324f32b17e33b837aa43d37cd0b6bbab6fc4b
4
- data.tar.gz: 985a3e86686c326fa816db8fcef1385ccc8c5372ac740f46992a9a019685f451
3
+ metadata.gz: 9cd5c4d072690acf0846ea8a6c0d34af8857073debf4c8c2d5a5688d92133038
4
+ data.tar.gz: 0ea211c29fbc8dcb0305368da6ae654c35404e498b1816d8507695e9a9a0e9e2
5
5
  SHA512:
6
- metadata.gz: e0ac5582359acf8fe7c5fb3391c9970e4dcd93f7e2742d92b8b558b2f4c840a9589ed6c157d115f6a98170a5865aa50457078eea2266cfde526b5a8b97630c33
7
- data.tar.gz: 6af6b00555bc59d5745eba085ce599782b08f6bb5e33982fcd07b260ce9ca1f3df062bc6ee05514f737ec24ebd9ad9b422c94839e76e07871fa75b206e476552
6
+ metadata.gz: 8c164cb1b0ab93492b055b20f9864ef2dfd0fbd3197bfe658c2a29b68df7cfd0fe06a5f8c4867b8e6e39826972190998385fd691178d2a502122f2b2f13d7cbf
7
+ data.tar.gz: e649301128cd231e73ddcd815b32359a658233fb334413f38c083bcf2c54f8b62836f9187abb8cfced19318588737128218fdcf0f46e92ff14728f20ce24df5c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.5.2
1
+ ### 0.5.3
2
2
  ### 0.0.1 / 2025-01-02
3
3
 
4
4
  * Everything is new. First release.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
2
2
 
3
3
 
4
4
  Hoe.spec 'fbtok' do
5
- self.version = '0.5.2'
5
+ self.version = '0.5.3'
6
6
 
7
7
  self.summary = "fbtok - football.txt lint tools incl. tokenizer, parser & more"
8
8
  self.description = summary
@@ -4,11 +4,18 @@ module Fbtree
4
4
  def self.main( args=ARGV )
5
5
 
6
6
 
7
+
7
8
  opts = {
8
9
  debug: true,
10
+ ## warn: false,
11
+
12
+ json: false,
13
+ yaml: false,
14
+
9
15
  file: nil,
16
+ tty: false,
17
+
10
18
  seasons: [],
11
- ## warn: false,
12
19
  }
13
20
 
14
21
  parser = OptionParser.new do |parser|
@@ -29,6 +36,13 @@ parser = OptionParser.new do |parser|
29
36
  # end
30
37
 
31
38
 
39
+ parser.on( "-f FILE", "--file FILE",
40
+ "read datafiles (pathspecs) via .csv file") do |file|
41
+ opts[:file] = file
42
+ ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
43
+ opts[:debug] = false
44
+ end
45
+
32
46
  parser.on( "--seasons SEASONS",
33
47
  "filter by seasons (default: #{opts[:seasons]})") do |seasons|
34
48
  opts[:seasons] = seasons
@@ -36,13 +50,20 @@ parser = OptionParser.new do |parser|
36
50
  .map { |season| Season.parse(season.strip) }
37
51
  end
38
52
 
39
- parser.on( "-f FILE", "--file FILE",
40
- "read datafiles (pathspecs) via .csv file") do |file|
41
- opts[:file] = file
42
- ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
43
- opts[:debug] = false
53
+
54
+ parser.on( "-j", "--json",
55
+ "turn on output in json (default: #{opts[:json]})" ) do |json|
56
+ opts[:json] = true
57
+ end
58
+ parser.on( "-y", "--yaml",
59
+ "turn on output in yaml (default: #{opts[:yaml]})" ) do |yaml|
60
+ opts[:yaml] = true
44
61
  end
45
62
 
63
+ parser.on( "-t", "--terminal", "--tty",
64
+ "force terminal/tty input (default: #{opts[:tty]})" ) do |tty|
65
+ opts[:tty] = tty
66
+ end
46
67
  end
47
68
  parser.parse!( args )
48
69
 
@@ -55,6 +76,59 @@ end
55
76
 
56
77
 
57
78
 
79
+ ## special case for typed input via terminal/tty
80
+ if opts[:tty]
81
+
82
+ puts "type your football.TXT lines here (exit with ctrl-z and return):"
83
+ lines = STDIN.readlines ## note - readlines incl. trailing newline!
84
+
85
+ txt = lines.join ## note - join with no space (already incl. trailing newline!)
86
+
87
+ puts "--- parsing #{lines.size} line(s) ---"
88
+ puts txt
89
+ puts "--- results ---"
90
+
91
+ tree, errors = parse_with_errors( txt, opts )
92
+
93
+ if errors.size > 0
94
+ puts
95
+ pp errors
96
+ puts
97
+ puts "!! #{errors.size} parse error(s)"
98
+ exit 1
99
+ else
100
+ puts
101
+ puts "OK no parse errors found"
102
+ exit 0
103
+ end
104
+ end
105
+
106
+
107
+
108
+ ## check for piped input e.g. $ curl | fbtree
109
+ if !STDIN.tty? ## input NOT via tty (teletype terminal)
110
+
111
+ txt = STDIN.read
112
+
113
+ puts "--- parsing ---"
114
+ puts txt
115
+ puts "--- results ---"
116
+
117
+ tree, errors = parse_with_errors( txt, opts )
118
+
119
+ if errors.size > 0
120
+ puts
121
+ pp errors
122
+ puts
123
+ puts "!! #{errors.size} parse error(s)"
124
+ exit 1
125
+ else
126
+ puts
127
+ puts "OK no parse errors found"
128
+ exit 0
129
+ end
130
+ end
131
+
58
132
 
59
133
 
60
134
 
@@ -108,20 +182,17 @@ specs.each_with_index do |rec,i|
108
182
  puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
109
183
 
110
184
  txt = read_text( path )
111
- parser = RaccMatchParser.new( txt, debug: opts[:debug] )
112
- tree = parser.parse
113
-
114
- dump_tree_stats( tree )
185
+ tree, more_errors = parse_with_errors( txt, opts )
115
186
 
116
- if parser.errors?
187
+ if more_errors.size > 0
117
188
  ## note - auto-add filename to errors
118
- parser.errors.each do |msg|
189
+ more_errors.each do |msg|
119
190
  ###
120
191
  ### errors << [ path, *msg ] # note: use splat (*) to add extra values (starting with msg)
121
192
  errors << [path, msg]
122
193
  end
123
194
 
124
- log << [:ERROR, path, "#{parser.errors.size} parse error(s), #{tree.size} tree node(s)"]
195
+ log << [:ERROR, path, "#{more_errors.size} parse error(s), #{tree.size} tree node(s)"]
125
196
  else
126
197
  log << [:OK, path, "#{tree.size} tree node(s)"]
127
198
  end
@@ -184,4 +255,31 @@ def self.dump_tree_stats( tree )
184
255
  end
185
256
 
186
257
 
258
+
259
+ def self.parse_with_errors( txt, opts={} )
260
+ parser = RaccMatchParser.new( txt, debug: opts[:debug] )
261
+ tree = parser.parse
262
+
263
+ dump_tree_stats( tree )
264
+
265
+ if opts[:yaml]
266
+ puts "--- yaml ---"
267
+ puts YAML.dump( tree )
268
+ end
269
+
270
+ if opts[:json]
271
+ puts "--- json ---"
272
+ ## puts JSON.pretty_generate( tree )
273
+ ##
274
+ ## note - use hacky but more beautiful pretty_print
275
+ txtjson = tree.as_json.pretty_inspect
276
+ txtjson = txtjson.gsub( '=>', ': ' )
277
+ puts txtjson
278
+ end
279
+
280
+
281
+ [tree, parser.errors]
282
+ end
283
+
284
+
187
285
  end # module Fbtree
@@ -1,33 +1,5 @@
1
1
 
2
2
 
3
- ##
4
- ## note - add find_dir( name, path: ) helper
5
- ## move upstream into cocos - why? why not?
6
- def find_dir( name, path: [] )
7
- return File.expand_path( name ) if Dir.exist?( name )
8
-
9
- ## note - if name starts with / or \ assume it's absolute!!
10
- ## do NOT search!!!
11
- ## note - search still works for
12
- ## ./austria or ../austria or such
13
- ##
14
- ## todo/check/fix-fix-fix
15
- ## is there a File.absolute? or such method for reuse??
16
- ##
17
- ## todo/fix-fix-fix add absolute check upstream to find_file too!!!
18
- return nil if name.start_with?( %r{[/\\]} )
19
-
20
- path.each do |basedir|
21
- ## todo/check - always make sure basedir is an absolute/expanded path - why? why not?
22
- dirpath = File.expand_path( name, basedir )
23
- return dirpath if Dir.exist?( dirpath )
24
- end
25
-
26
- nil ## return nil if not found
27
- end
28
-
29
-
30
-
31
3
 
32
4
 
33
5
  module SportDb
@@ -161,6 +133,15 @@ def self.find( path, seasons: nil )
161
133
  next if /squad/i.match?( basename )
162
134
  next if /\.v[0-9][0-9_]*/i.match?( basename )
163
135
 
136
+ ### exclude
137
+ ## logs.txt or logs.xxx.txt etc
138
+ ## log.txt or log.xxx.txt etc
139
+ ## -or-
140
+ ## errors.txt or errors.xxx.txt etc
141
+ next if /^logs?($|\.)/i.match?( basename )
142
+ next if /^errors?($|\.)/i.match?( basename )
143
+
144
+
164
145
  #####
165
146
  ### exclude dirs with:
166
147
  ## - squad or wiki
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbtok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-11 00:00:00.000000000 Z
11
+ date: 2026-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-parser