Class: Lf::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/lf/filter.rb

Direct Known Subclasses

Eq, Ignore, Label, Regexp

Defined Under Namespace

Classes: Eq, Ignore, Label, Regexp

Constant Summary collapse

FILTERS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Filter

Returns a new instance of Filter.



36
37
38
# File 'lib/lf/filter.rb', line 36

def initialize(arg)
  @arg = arg
end

Class Method Details

.[](name) ⇒ Object



14
15
16
# File 'lib/lf/filter.rb', line 14

def self.[](name)
  FILTERS[name.to_s.to_sym]
end

.[]=(name, klass) ⇒ Object



18
19
20
# File 'lib/lf/filter.rb', line 18

def self.[]=(name, klass)
  FILTERS[name.to_s.to_sym] = klass
end

.filter_alias(name) ⇒ Object



10
11
12
# File 'lib/lf/filter.rb', line 10

def self.filter_alias(name)
  Lf::Filter[name] = self
end

.inherited(klass) ⇒ Object



6
7
8
# File 'lib/lf/filter.rb', line 6

def self.inherited(klass)
  Lf::Filter[klass.name.sub(/.*::/, '').downcase] = klass
end

.parse(argv) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lf/filter.rb', line 22

def self.parse(argv)
  filters = []

  argv.each do |arg|
    arg = arg.sub(/^([^:]*):/, '')
    if ::Regexp.last_match && ::Regexp.last_match[1]
      name = ::Regexp.last_match[1].to_s.to_sym
      filters << self[name].new(arg) if self[name]
    end
  end

  filters
end

Instance Method Details

#apply(row) ⇒ Object



40
41
42
# File 'lib/lf/filter.rb', line 40

def apply(row)
  row
end