Top Level Namespace

Defined Under Namespace

Modules: Fbfind, Fbquick, Fbtok, Fbtree, Fbx, SportDb

Constant Summary collapse

FILEPACK_HEADER_RE =

PACK eng|en

add NAME eng|en   - why? why not?

change to FILEPACK_NAME - why? why not?

%r{\A
    (?: PACK ) [ ]+
    (?<header> .+?)   ## note - use non-greedy
\z}x
FILEPACK_DIR_RE =

DIR /sports/openfootball

CD  /sports/openfootball     -- keep - why? why not?
%r{\A
        (?: DIR|CD ) [ ]+
        (?<dir> .+? )      ## note - use non-greedy

\z}x

Instance Method Summary collapse

Instance Method Details

#build_pathspecs(args, path: [], filepack: nil) ⇒ Object

build pathspecs via arguments

- (i) every dir is a pathspec entry/record
- (ii) all files get bundled together into <input> pathspec entry/record

note: was formerly known as expand_args


316
317
318
# File 'lib/fbtok/pathspec.rb', line 316

def build_pathspecs( args, path: [], filepack: nil )
   SportDb::Pathspecs.build( args, path: path, filepack: filepack )
end

#filter_pathspecs(specs, seasons:) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/fbtok/pathspec.rb', line 328

def filter_pathspecs( specs, seasons: )
    ## norm seasons
    seasons =  seasons.map {|season| Season(season) }

    ##  todo/fix: auto-add/update  rec['seasons'] column - why? why not?

    ## note - filter datafiles inplace!!!
    specs.each do |rec|
       rec['datafiles'] =
       rec['datafiles'].select do |candidate|
             m=SportDb::Pathspec::MATCH_RE.match( candidate )
             if m && seasons.include?( Season.parse( m[:season] ))
                true
             else
                false
             end
        end
    end

    specs
end

#find_dir(name, path: []) ⇒ Object

note - add find_dir( name, path: ) helper

move upstream into cocos - why? why not?


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fbtok/pathspec.rb', line 6

def find_dir( name, path: [] )
    return File.expand_path( name )     if Dir.exist?( name )

##  note - if name starts with / or \ assume it's absolute!!
##    do NOT search!!!
##     note - search still works for
##               ./austria  or ../austria or such
##
##  todo/check/fix-fix-fix
##     is there a File.absolute? or such method for reuse??
##
##  todo/fix-fix-fix add absolute check upstream to find_file too!!!
    return nil    if name.start_with?( %r{[/\\]} )

    path.each do |basedir|
        ## todo/check -  always make sure basedir is an absolute/expanded path - why? why not?
        dirpath = File.expand_path( name, basedir )
        return dirpath   if Dir.exist?( dirpath )
    end

    nil   ## return nil if not found
end

#parse_filepack(txt) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fbtok/filepack.rb', line 30

def parse_filepack( txt )
    h={}
    recs    = nil
    basedir = nil

    txt.each_line do |line|
      line = line.strip

      next  if line.start_with?('#') || line.empty?

      break if line == '__END__'


      if m=FILEPACK_HEADER_RE.match(line)
        keys    = m[:header].strip.split(  /[ ]*\|[ ]*/ )
        basedir = nil
        recs = []
        ## note - normalize keys for now (always downcase)
        keys.each {|key| h[key.downcase] = recs }
      elsif m=FILEPACK_DIR_RE.match(line)
        basedir = m[:dir].strip
      else
        file =  basedir ? File.join( basedir, line ) : line
        recs << file
      end
    end

    h
end

#read_filepack(path) ⇒ Object



61
62
63
# File 'lib/fbtok/filepack.rb', line 61

def read_filepack( path )
  parse_filepack( read_text( path ))
end

#read_pathspecs(src) ⇒ Object

read pathspecs via csv file (using path column)



322
323
324
# File 'lib/fbtok/pathspec.rb', line 322

def read_pathspecs( src )
    SportDb::Pathspecs.read( src )
end