Class: FileFinder

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/slideshow/cli/main_utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FileFinder

Returns a new instance of FileFinder.



18
19
20
# File 'lib/slideshow/cli/main_utils.rb', line 18

def initialize( config )
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/slideshow/cli/main_utils.rb', line 22

def config
  @config
end

Instance Method Details

#find_file_with_known_extension(fn) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slideshow/cli/main_utils.rb', line 24

def find_file_with_known_extension( fn )
  dirname  = File.dirname( fn )
  basename = File.basename( fn, '.*' )
  extname  = File.extname( fn )
  logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"

  config.known_extnames.each do |e|
    newname = File.join( dirname, "#{basename}#{e}" )
    logger.debug "File.exists? #{newname}"
    return newname if File.exists?( newname )
  end  # each extension (e)
    
  nil   # not found; return nil
end

#find_files(file_or_dir_or_pattern) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/slideshow/cli/main_utils.rb', line 40

def find_files( file_or_dir_or_pattern )
  filtered_files = []
 
  ## for now process/assume only single file
  
  ## (check for missing extension)
  if File.exists?( file_or_dir_or_pattern )
    file = file_or_dir_or_pattern
    logger.debug "  adding file '#{file}'..."
    filtered_files << file
  else  # check for existing file w/ missing extension
    file = find_file_with_known_extension( file_or_dir_or_pattern )
    if file.nil?
      puts "  skipping missing file '#{file_or_dir_or_pattern}{#{config.known_extnames.join(',')}}'..."
    else
      logger.debug "  adding file '#{file}'..."
      filtered_files << file
    end
  end
  
  filtered_files 
end