Class: Iudex::Filter::ProcFilter

Inherits:
FilterBase show all
Defined in:
lib/iudex-filter/proc_filter.rb

Overview

A filter wrapping a Ruby Proc.

Constant Summary

Constants included from Iudex::Filter

LIB_DIR, VERSION

Instance Method Summary collapse

Methods inherited from FilterBase

#name

Methods included from Iudex::Filter

#fltr, #fltr_method

Constructor Details

#initialize(opts = {}, &block) ⇒ ProcFilter

Use block as implementation of filter(map). The filter will only return false (reject map, stop chain) if the block returns the :reject symbol. All other return values are ignored, including “false”.

Options

Passing a String for opts is interpreted as :caller (deprecated as of 1.3.0)

:caller

String from which to compose the description. This is used under Ruby 1.8 only, obtained via block.source_location in 1.9.

:desc

Array<~to_s> description (overrides caller)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/iudex-filter/proc_filter.rb', line 52

def initialize( opts = {}, &block )
  @block = block

  opts = { :caller => opts } if opts.is_a?( String )
  @description = Array( opts[ :desc ] ).compact

  if @description.empty?
    if @block.respond_to?( :source_location ) # ruby 1.9
      clr = @block.source_location
    else                                      # ruby 1.8
      clr = opts[ :caller ] || caller.first
      clr = clr.split( /:/ )
    end

    @description = [ File.basename( clr[0], ".rb" ), clr[1].to_i ]
  end

end

Instance Method Details

#describeObject



71
72
73
# File 'lib/iudex-filter/proc_filter.rb', line 71

def describe
  @description
end

#filter(map) ⇒ Object

Calls initialized block, returning true if it returns anything but :reject



77
78
79
# File 'lib/iudex-filter/proc_filter.rb', line 77

def filter( map )
  ( @block.call( map ) != :reject )
end