From 3652e290b98f34ea9d4b3a428e496ebd81714372 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 7 Jan 2010 21:46:03 -0500 Subject: [PATCH] verify filename --- classes/ConfigLoader.rb | 2 -- classes/FileProcessor.rb | 70 +++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/classes/ConfigLoader.rb b/classes/ConfigLoader.rb index a3db718..70eb6a0 100644 --- a/classes/ConfigLoader.rb +++ b/classes/ConfigLoader.rb @@ -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 diff --git a/classes/FileProcessor.rb b/classes/FileProcessor.rb index c73e83a..78f1fa7 100644 --- a/classes/FileProcessor.rb +++ b/classes/FileProcessor.rb @@ -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