Class: SClust::Util::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/sclust/util/filters.rb

Defined Under Namespace

Classes: StemmedWord

Instance Method Summary collapse

Constructor Details

#initialize(prev = nil) ⇒ Filter

Returns a new instance of Filter.



85
86
87
88
# File 'lib/sclust/util/filters.rb', line 85

def initialize(prev=nil)
    @previous_filters = (prev)? [ prev ] : []
    @succeeding_filters = []
end

Instance Method Details

#after(filter) ⇒ Object



106
107
108
109
# File 'lib/sclust/util/filters.rb', line 106

def after(filter)
    @previous_filters << filter
    self
end

#apply(term) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/sclust/util/filters.rb', line 90

def apply(term)
    
    if ( term )
        
        catch(:filtered_term) do
            @previous_filters.each { |f| term = f.filter(term) ; throw :filtered_term if term.nil? }
            
            term = filter(term) ; throw :filtered_term if term.nil?
            
            @succeeding_filters.each { |f| term = f.filter(term) ; throw :filtered_term if term.nil? }
        end
    end
    
    term
end

#before(filter) ⇒ Object



111
112
113
114
# File 'lib/sclust/util/filters.rb', line 111

def before(filter)
    @succeeding_filters << filter
    self
end

#filter(term) ⇒ Object

Raises:

  • (Exception)


116
117
118
# File 'lib/sclust/util/filters.rb', line 116

def filter(term)
    raise Exception.new("Method \"filter\" must be overridden by child classes to implement the specific filter.")
end