Changeset 174

Show
Ignore:
Timestamp:
04/19/08 12:22:52 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Some doc for models/filter.rb

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/oo_indexer/lib/picolena/templates/app/models/filter.rb

    r172 r174  
    44  include FilterDSL 
    55  @@filters=[] 
    6    
    7   #returns every defined filter 
    8   def self.all 
     6  class<<self  
     7  # Returns every defined filter 
     8  def all 
    99    @@filters 
    1010  end 
    11  
    12   def self.add(filter) 
     11   
     12  # Add a filter to the filters list 
     13  def add(filter) 
    1314    @@filters<<filter 
    1415  end 
    1516 
    16   def self.each(&block) 
     17  # Calls block for each filter 
     18  def each(&block) 
    1719    all.each(&block) 
    1820  end 
    1921   
    20   #returns every required dependency for every defined filter 
    21   def self.dependencies 
     22  # Returns every required dependency for every defined filter 
     23  def dependencies 
    2224    @@dependencies||=all.collect{|filter| filter.dependencies}.flatten.compact.uniq.sort 
    2325  end 
    2426   
    25   #returns every supported file extensions 
    26   def self.supported_extensions 
     27  # Returns every supported file extensions 
     28  def supported_extensions 
    2729    @@supported_exts||=all.collect{|filter| filter.exts}.flatten.compact.uniq 
    2830  end 
    2931 
    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) 
    3235    ext=File.ext_as_sym(filename) 
    3336    filter=all.find{|filter| filter.exts.include?(ext)} || raise(ArgumentError, "no convertor for #{filename}") 
     
    3639  end 
    3740   
    38   #launches filter on given file and outputs plain text result 
    39   def self.extract_content_from(source) 
    40     find_filter_for(source).extract_content 
     41  # Launches filter on given file and outputs plain text result 
     42  def extract_content_from(source) 
     43    find_by_filename(source).extract_content 
    4144  end 
     45  end 
     46 
    4247   
    4348   
    4449    attr_accessor :source 
    4550     
    46     #parses command in order to know which programs are needed. 
    47     #rspec will then check that every dependecy is installed on the system 
     51    # Parses command in order to know which programs are needed. 
     52    # rspec will then check that every dependecy is installed on the system 
    4853    def dependencies 
    4954      if command.is_a?(String) then 
     
    5459    end 
    5560     
    56     #Conversion part 
     61    ## Conversion part 
    5762     
    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. 
    6065    def destination 
    6166      require 'tmpdir' 
     
    6368    end 
    6469     
    65     #Replaces generic command with specific source and destination (if specified) files 
     70    # Replaces generic command with specific source and destination (if specified) files 
    6671    def specific_command 
    6772      command.sub('SOURCE','"'<<source<<'"').sub('DESTINATION','"'<<destination<<'"') 
    6873    end 
    69      
     74    
     75    # Returns plain text content of source file 
    7076    def extract_content 
    7177      if command.is_a?(String) then