class Datafile::DirPackage

Attributes

name[R]
path[R]

Public Class Methods

new( path ) click to toggle source
# File lib/sportdb/formats/datafile_package.rb, line 39
def initialize( path )
  ## todo/fix:  expand_path ?! - why? why not? if you pass in ./ basename will be . and NOT directory name, for example!!!
  @path = path   ## rename to root_path or base_path or somehting - why? why not?

  basename = File.basename( path )   ## note: ALWAYS keeps "extension"-like name if present (e.g. ./austria.zip => austria.zip)
  @name = basename
end

Public Instance Methods

each( pattern: ) { |entry| ... } click to toggle source

todo/check: change pattern: to re: - why? why not?

# File lib/sportdb/formats/datafile_package.rb, line 48
def each( pattern: )    ## todo/check: rename to glob or something - why? why not?
  ##   use just .* for extension or remove and check if File.file? and skip File.directory? - why? why not?
  ## note: incl. files starting with dot (.)) as candidates (normally excluded with just *)
  ##   todo/check/fix:   is there a better (simpler) glob pattern?  yes? no?
  Dir.glob( "#{@path}/**/{*,.*}.*" ).each do |path|
    if File.directory?( path )
       ## always skip directories / folders
    elsif EXCLUDE_RE.match( path )
       ## note: skip dot dirs (e.g. .build/, .git/, etc.)
    elsif pattern.match( path )
      yield( Entry.new( self, path ))
    else
       ## puts "  skipping >#{path}<"
    end
  end
end
find( name ) click to toggle source
# File lib/sportdb/formats/datafile_package.rb, line 65
def find( name )
  Entry.new( self, "#{@path}/#{name}" )
end