verify filename

This commit is contained in:
John Bintz 2010-01-07 21:46:03 -05:00
parent fe9330f50e
commit 3652e290b9
2 changed files with 47 additions and 25 deletions

View File

@ -20,8 +20,6 @@ class ConfigLoader
fileinfo_by_file = {}
if global['pages']
re = nil
files = global['pages'].collect do |f|
result = nil
case f.class.to_s

View File

@ -1,29 +1,19 @@
class FileProcessor
attr_accessor :config, :paginated_source_files, :page_index
def initialize(config)
@page_index = 0
@config = config
@paginated_source_files = {}
end
def process
paginated_source_files = {}
rsync_files_by_target = {}
files.each do |filename|
ok = true; matches = nil; fileinfo = {}
if filename.instance_of? Hash
if filename['blank']
ok = false
config.each do |type, info|
if info['is_paginated']
if !paginated_source_files[type]; paginated_source_files[type] = []; end
paginated_source_files[type] << nil
end
end
page_index += 1
else
fileinfo = filename
filename = fileinfo['file']
end
else
if re; ok = matches = re.match(filename); end
end
ok, fileinfo, filename = verify_filename(filename)
if ok
filename_display = (filename.instance_of? Array) ? filename.join(", ") : filename
@ -31,11 +21,11 @@ class FileProcessor
puts "Examining #{filename_display}..."
filename_parts = {
'page_index' => sprintf(page_index_format, page_index)
'page_index' => sprintf(page_index_format, @page_index)
}
if matches
all, index, title = matches.to_a
if @config['Global']['match']
all, index, title = ok.to_a
else
index = page_index - 1
title = ""
@ -152,4 +142,38 @@ class FileProcessor
end
end
def verify_filename(filename)
ok = true
fileinfo = {}
if filename.instance_of? Hash
if filename['blank']
ok = false
@config.each do |type, info|
if info['is_paginated']
if !@paginated_source_files[type]
@paginated_source_files[type] = []
end
@paginated_source_files[type] << nil
end
end
@page_index += 1
else
if filename['file']
fileinfo = filename
filename = fileinfo['file']
else
ok = false
end
end
else
if @config['Global']
if @config['Global']['match']
ok = Regexp.new(@config['Global']['match']).match(filename)
end
end
end
[ ok, fileinfo, filename ]
end
end