Module: Jcsv::NextFilter

Included in:
Filter, RBParseBool, RBParseChar, RBParseDouble, RBParseInt, RBParseLong, RBParseRFC822
Defined in:
lib/filters.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_filterObject

last_filter is a variable that points to the last filter in the sequence of filters. It is necessary to build the linked list of filters



66
67
68
# File 'lib/filters.rb', line 66

def last_filter
  @last_filter
end

#next_filterObject

This object’s next filter



62
63
64
# File 'lib/filters.rb', line 62

def next_filter
  @next_filter
end

Instance Method Details

#>>(next_filter) ⇒ Object


Method >> is used to link one filter to the next filter. Basically we keep a linked list of filters.




73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/filters.rb', line 73

def >>(next_filter)
  if (@next_filter.nil?)
    @next_filter = next_filter
    # this check is necessary in the following case: a >> (b >> c) >> d.  In
    # principle one has no reason to use parenthesis, but if done, then this check
    # should make everything still work fine
    @last_filter = (next_filter.last_filter.nil?)? @next_filter :
                     @next_filter.last_filter
  else
    @last_filter.next_filter = next_filter
    @last_filter = next_filter        
  end
  self
end

#exec_next(value, context) ⇒ Object


Executes the next filter




92
93
94
# File 'lib/filters.rb', line 92

def exec_next(value, context)
  @next_filter? @next_filter.execute(value, context) : value      
end