Class: SportDb::Pathspec
- Inherits:
-
Object
- Object
- SportDb::Pathspec
- Defined in:
- lib/fbtok/pathspec.rb
Constant Summary collapse
- SEASON_RE =
%r{ (?: (?<season>\d{4}-\d{2}) | (?<season>\d{4}) ) }x- 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? note - support case-insensitive flag (e.g. 2025-26/namur/2_Prov_A.txt) %r{ ## "classic" variant i) with season folder ## e.g. /1930/cup.txt (?: (?: ^|/ ) # beginning (^) or beginning of path (/) #{SEASON_RE} (?: --[a-z0-9_-]+ )? / ### note - allow optional directories (?: [a-z0-9][a-z0-9_-]* / )* [a-z0-9][a-z0-9._-]* \.txt ## e.g /1-premierleague.txt $ ) | ## "compact" variant ii) with season in filename ## e.g. 1930.txt or 2024_br.txt etc. (?: (?: ^|/ ) # beginning (^) or beginning of path (/) #{SEASON_RE} (?: _ ## allow more than one underscore - why? why not? [a-z0-9][a-z0-9._-]* )? \.txt $ ) }xi
Class Method Summary collapse
- ._find(path, seasons: nil) ⇒ Object
- ._norm_seasons(seasons) ⇒ Object
- .debug=(value) ⇒ Object
-
.debug? ⇒ Boolean
note: default is FALSE.
- .read(src) ⇒ Object
Class Method Details
._find(path, seasons: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/fbtok/pathspec.rb', line 77 def self._find( path, seasons: nil ) ## check - rename dir ## use root_dir or work_dir or cd or such - why? why not? ## note: normalize path - use File.expand_path ?? ## change all backslash to slash for now ## path = path.gsub( "\\", '/' ) path = File.( path ) #### ## note - make sure path exists; raise error if not raise Errno::ENOENT, "No such directory - #{path})" unless Dir.exist?( path ) if seasons && seasons.size > 0 seasons = _norm_seasons( seasons ) ## norm seasons (string, integer => Season obj) end ## check all txt files ## note: incl. files starting with dot (.)) as candidates ## (normally excluded with just *) ## was: Dir.glob( "#{path}/**/{*,.*}.txt" ) candidates = Dir.glob( "#{path}/**/*.txt" ) ## pp candidates datafiles = [] candidates.each do |candidate| if m = MATCH_RE.match( candidate ) ## check for seasons filter next if seasons && seasons.size > 0 && !seasons.include?( Season.parse( m[:season] )) ######### ### exclude squad ## and .v2 or .v2603 ## ## - worldcup/more/1930_squads.txt => squads ## - 2014--brazil/cup.v2.txt", ## - 2014--brazil/cup.v260318_164934.txt", basename = File.basename( candidate, File.extname( candidate )) next if /squad/i.match( basename ) next if /\.v[0-9][0-9_]*/i.match( basename ) ##### ### exclude dirs w/ squad or wiki dirname = File.dirname( candidate ) next if /squad|wiki/i.match( dirname ) datafiles << candidate end end ## pp datafiles datafiles end |
._norm_seasons(seasons) ⇒ Object
65 66 67 |
# File 'lib/fbtok/pathspec.rb', line 65 def self._norm_seasons( seasons ) seasons.map {|season| Season(season) } end |
.debug=(value) ⇒ Object
7 |
# File 'lib/fbtok/pathspec.rb', line 7 def self.debug=(value) @@debug = value; end |
.debug? ⇒ Boolean
note: default is FALSE
8 |
# File 'lib/fbtok/pathspec.rb', line 8 def self.debug?() @@debug ||= false; end |
.read(src) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fbtok/pathspec.rb', line 147 def self.read( src ) 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 ) datafiles = _find( fullpath ) ## add (new) datafiles column (from expanded pathspec) rec['datafiles'] = datafiles end recs end |