Module: QDA::Filters

Defined in:
lib/weft/filters.rb,
lib/weft/filters/input.rb,
lib/weft/filters/output.rb,
lib/weft/filters/templates.rb,
lib/weft/filters/win32backtick.rb

Defined Under Namespace

Modules: PDFReader, TemplatedOutput, Templates, TextReader, Win32Process Classes: CategoryOutputFilter, CodeReviewCSVOutput, CodeReviewOutputFilter, DocumentOutputFilter, DocumentTextFilter, OutputFilter, PDFFileDocumentFilter, TextFileDocumentFilter

Constant Summary collapse

@@import =
Hash.new { |  h, k | h[k] = [] }
@@export =
Hash.new { |  h, k | h[k] = [] }

Class Method Summary collapse

Class Method Details

.can_export?(weft_class) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/weft/filters.rb', line 58

def can_export?(weft_class)
  @@export.has_key?(weft_class)
end

.export_filtersObject

Returns a hash of all available export filter types, keyed on Weft classes (eg Document)



46
47
48
# File 'lib/weft/filters.rb', line 46

def export_filters()
  @@export
end

.find_export_filter(weft_class, ext) ⇒ Object



54
55
56
# File 'lib/weft/filters.rb', line 54

def find_export_filter( weft_class, ext )
  @@export[weft_class].find { | filter | filter::EXTENSION == ext }
end

.find_import_filter(weft_class, ext) ⇒ Object



50
51
52
# File 'lib/weft/filters.rb', line 50

def find_import_filter( weft_class, ext )
  @@import[weft_class].find { | filter | filter::EXTENSIONS.include?(ext) }
end

.import(filter, content) {|obj, filter| ... } ⇒ Object

Yields:

  • (obj, filter)


31
32
33
34
35
# File 'lib/weft/filters.rb', line 31

def import(filter, content)
  obj = filter.run(content)
  yield obj, filter if block_given?
  obj
end

.import_file(klass, filename, opts = {}, &block) ⇒ Object

imports an object of class klass e.g. QDA::Document from the file filename, which should be a string.



22
23
24
25
26
27
28
29
# File 'lib/weft/filters.rb', line 22

def import_file(klass, filename, opts = {}, &block)
  ext = filename[-3,3]
  filter_class = Filters.find_import_filter(klass, ext)
  if not filter_class
    raise FilterError.new("Cannot import a file of type '#{ext}'")
  end
  import(filter_class.new(), filename, &block)
end

.import_filtersObject

Returns a hash of all available import filter types, keyed on Weft classes (eg Document



39
40
41
# File 'lib/weft/filters.rb', line 39

def import_filters()
  @@import
end

.register_filter(filter_class) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/weft/filters.rb', line 11

def register_filter( filter_class )
  if defined? filter_class::IMPORT_CLASS
    @@import[filter_class::IMPORT_CLASS].push(filter_class)
  end
  if defined? filter_class::EXPORT_CLASS
    @@export[filter_class::EXPORT_CLASS].push(filter_class)
  end
end