Changeset 174
- Timestamp:
- 04/19/08 12:22:52 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/oo_indexer/lib/picolena/templates/app/models/filter.rb
r172 r174 4 4 include FilterDSL 5 5 @@filters=[] 6 7 # returns every defined filter8 def self.all6 class<<self 7 # Returns every defined filter 8 def all 9 9 @@filters 10 10 end 11 12 def self.add(filter) 11 12 # Add a filter to the filters list 13 def add(filter) 13 14 @@filters<<filter 14 15 end 15 16 16 def self.each(&block) 17 # Calls block for each filter 18 def each(&block) 17 19 all.each(&block) 18 20 end 19 21 20 # returns every required dependency for every defined filter21 def self.dependencies22 # Returns every required dependency for every defined filter 23 def dependencies 22 24 @@dependencies||=all.collect{|filter| filter.dependencies}.flatten.compact.uniq.sort 23 25 end 24 26 25 # returns every supported file extensions26 def s elf.supported_extensions27 # Returns every supported file extensions 28 def supported_extensions 27 29 @@supported_exts||=all.collect{|filter| filter.exts}.flatten.compact.uniq 28 30 end 29 31 30 #finds which filter should be used for a given file, according to its extension 31 def self.find_filter_for(filename) 32 # Finds which filter should be used for a given file, according to its extension 33 # Raises if the file is unsupported. 34 def find_by_filename(filename) 32 35 ext=File.ext_as_sym(filename) 33 36 filter=all.find{|filter| filter.exts.include?(ext)} || raise(ArgumentError, "no convertor for #{filename}") … … 36 39 end 37 40 38 # launches filter on given file and outputs plain text result39 def self.extract_content_from(source)40 find_ filter_for(source).extract_content41 # Launches filter on given file and outputs plain text result 42 def extract_content_from(source) 43 find_by_filename(source).extract_content 41 44 end 45 end 46 42 47 43 48 44 49 attr_accessor :source 45 50 46 # parses command in order to know which programs are needed.47 # rspec will then check that every dependecy is installed on the system51 # Parses command in order to know which programs are needed. 52 # rspec will then check that every dependecy is installed on the system 48 53 def dependencies 49 54 if command.is_a?(String) then … … 54 59 end 55 60 56 # Conversion part61 ## Conversion part 57 62 58 # destination method can be used by some conversion command that cannot output to stdout (example?)59 # a file containing plain text result will first be written by command, and then be read by extract_content.63 # destination method can be used by some conversion command that cannot output to stdout (example?) 64 # a file containing plain text result will first be written by command, and then be read by extract_content. 60 65 def destination 61 66 require 'tmpdir' … … 63 68 end 64 69 65 # Replaces generic command with specific source and destination (if specified) files70 # Replaces generic command with specific source and destination (if specified) files 66 71 def specific_command 67 72 command.sub('SOURCE','"'<<source<<'"').sub('DESTINATION','"'<<destination<<'"') 68 73 end 69 74 75 # Returns plain text content of source file 70 76 def extract_content 71 77 if command.is_a?(String) then
