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
Class Method Details
.find(path, seasons: nil) ⇒ Object
69 70 71 72 73 74 75 76 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 142 143 144 145 |
# File 'lib/fbtok/pathspec.rb', line 69 def self.find( path, seasons: nil ) ## ## note - only if seasons filter is turn on ## MATCH_RE gets used!!! ## otherwise generic **/*.txt ## ## note - the ignore/exlude filter always gets used/applied for now ## 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 fullpath = File.( path ) #### ## note - make sure path exists; raise error if not ## ENOENT => Error No Entity raise Errno::ENOENT, "No such directory - #{path})" unless Dir.exist?( fullpath ) if seasons && seasons.size > 0 ## norm seasons (string, integer => Season obj) seasons = seasons.map {|season| Season(season) } 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( "#{fullpath}/**/*.txt" ) ## pp candidates datafiles = [] candidates.each do |candidate| ## (i) check for (optional) seasons filter if seasons && seasons.size > 0 if m=MATCH_RE.match( candidate ) next unless seasons.include?( Season.parse( m[:season] )) else next ## note - no season found in filename; skip too end end ## (ii) check for (default/built-in) ignore/excludes basename = File.basename( candidate, File.extname( candidate )) dirname = File.dirname( candidate ) ### exclude basenames with: ## - squad ## - .v2 or .v2603 ## ## - worldcup/more/1930_squads.txt => squads ## - 2014--brazil/cup.v2.txt ## - 2014--brazil/cup.v260318_164934.txt next if /squad/i.match?( basename ) next if /\.v[0-9][0-9_]*/i.match?( basename ) ##### ### exclude dirs with: ## - squad or wiki next if /squad|wiki/i.match?( dirname ) datafiles << candidate end ## pp datafiles datafiles end |
.path(default = []) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fbtok/pathspec.rb', line 148 def self.path( default=[]) ## check for FBPATH ## or FBTXT_PATH path = ENV['FBPATH'] || ENV['FBTXT_PATH'] if path path.split( /[:;]/) else default end end |