Class: SportDb::Parser::Opts
- Inherits:
-
Object
- Object
- SportDb::Parser::Opts
- Defined in:
- lib/fbtok/opts.rb
Overview
note - Opts Helpers for now nested inside Parser - keep here? why? why not?
Defined Under Namespace
Classes: PathspecNode
Constant Summary collapse
- SEASON_RE =
%r{ (?: \d{4}-\d{2} | \d{4} (?: --[a-z0-9_-]+ )? ## todo/fix - allow "extension" to 2024-25 too - why? ) }x
- SEASON =
“inline” helper for embedding in other regexes - keep? why? why not?
SEASON_RE.source
- MATCH_RE =
note: if pattern includes directory add here
(otherwise move to more "generic" datafile) - why? why not? update - note include/allow dot (.) too BUT NOT as first character!!! (e.g. exclude .confg.txt !!!) e.g. 2024-25/at.1.txt change to at_1 or uefa_cl or such - why? why not? %r{ (?: ## "classic" variant i) with season folder (?: ^|/ ) # beginning (^) or beginning of path (/) #{SEASON} / [a-z0-9][a-z0-9_.-]*\.txt$ ## txt e.g /1-premierleague.txt ) | (?: ## "compact" variant ii) with season in filename (?: ^|/ ) # beginning (^) or beginning of path (/) (?: \d{4}-\d{2} | \d{4} ) _ ## allow more than one underscore - why? why not? [a-z0-9][a-z0-9_.-]*\.txt$ ) }x
Class Method Summary collapse
- ._expand(arg) ⇒ Object
- ._find(path) ⇒ Object
- .build_pathspec(paths:) ⇒ Object
- .debug=(value) ⇒ Object
-
.debug? ⇒ Boolean
note: default is FALSE.
- .expand_args(args) ⇒ Object
- .read_pathspecs(src) ⇒ Object
Class Method Details
._expand(arg) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fbtok/opts.rb', line 76 def self.( arg ) ## check if directory if Dir.exist?( arg ) datafiles = _find( arg ) if debug? puts puts " found #{datafiles.size} match txt datafiles in #{arg}" pp datafiles end datafiles else ## assume it's a file ## make sure path exists; raise error if not if File.exist?( arg ) [arg] ## note - always return an array - why? why not? else raise Errno::ENOENT, "No such file or directory - #{arg}" end end end |
._find(path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fbtok/opts.rb', line 50 def self._find( path ) ## check - rename dir ## use root_dir or work_dir or cd or such - why? why not? datafiles = [] ## note: normalize path - use File.expand_path ?? ## change all backslash to slash for now ## path = path.gsub( "\\", '/' ) path = File.( path ) ## check all txt files ## note: incl. files starting with dot (.)) as candidates ## (normally excluded with just *) candidates = Dir.glob( "#{path}/**/{*,.*}.txt" ) ## pp candidates candidates.each do |candidate| datafiles << candidate if MATCH_RE.match( candidate ) end ## pp datafiles datafiles end |
.build_pathspec(paths:) ⇒ Object
114 115 116 |
# File 'lib/fbtok/opts.rb', line 114 def self.build_pathspec( paths: ) PathspecNode.new( paths: paths, rec: {} ) end |
.debug=(value) ⇒ Object
10 |
# File 'lib/fbtok/opts.rb', line 10 def self.debug=(value) @@debug = value; end |
.debug? ⇒ Boolean
note: default is FALSE
11 |
# File 'lib/fbtok/opts.rb', line 11 def self.debug?() @@debug ||= false; end |
.expand_args(args) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/fbtok/opts.rb', line 97 def self.( args ) paths = [] args.each do |arg| paths += ( arg ) end paths end |
.read_pathspecs(src) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fbtok/opts.rb', line 118 def self.read_pathspecs( src ) specs = [] recs = read_csv( src ) pp recs if debug? ## note - make pathspecs relative to passed in file arg!!! basedir = File.dirname( src ) recs.each do |rec| path = rec['path'] fullpath = File.( path, basedir ) ## make sure path exists; raise error if not paths = if Dir.exist?( fullpath ) _find( fullpath ) else raise Errno::ENOENT, "No such directory - #{fullpath})" end specs << PathspecNode.new( paths: paths, rec: rec ) end specs end |