Class: Datafile::DirPackage
- Defined in:
- lib/sportdb/formats/datafile_package.rb
Overview
todo/check: find a better name e.g. UnzippedPackage, FilesystemPackage, etc. - why? why not?
Defined Under Namespace
Classes: Entry
Constant Summary
Constants inherited from Package
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#each(pattern:) ⇒ Object
todo/check: change pattern: to re: - why? why not?.
- #find(name) ⇒ Object
-
#initialize(path) ⇒ DirPackage
constructor
A new instance of DirPackage.
Methods inherited from Package
Constructor Details
#initialize(path) ⇒ DirPackage
Returns a new instance of DirPackage.
39 40 41 42 43 44 45 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/sportdb/formats/datafile_package.rb', line 37 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
37 38 39 |
# File 'lib/sportdb/formats/datafile_package.rb', line 37 def path @path end |
Instance Method Details
#each(pattern:) ⇒ Object
todo/check: change pattern: to re: - why? why not?
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |