Class: Chirp::LineProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/chirp/application.rb

Constant Summary collapse

DEFAULT_ACTION =
lambda { puts(line) }

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}, &block) ⇒ LineProcessor

Returns a new instance of LineProcessor.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/chirp/application.rb', line 75

def initialize(context, options={}, &block)

 @context = context
 @expression = options[:expr]
 @pattern = options[:pattern]
 @match = options[:match]
 @number = options[:number]
 if options[:start]
   @span = Span.new(options[:start], options[:end])
 else
   @span=nil
 end
 @options = options
 @block = block ||  DEFAULT_ACTION
end

Instance Method Details

#executeObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/chirp/application.rb', line 91

def execute
 if @match
   return unless @match == @context.line
 end
 if @pattern
   return unless @pattern =~ @context.line
 end
 if @number
   return unless @number == @context.line_no
 end
 if @expression
   return unless @context.execute(@expression)
 end
 if @span
   return unless @span.evaluate(@context)
 end
 @context.execute(@block)
end

#resetObject



110
111
112
# File 'lib/chirp/application.rb', line 110

def reset
  @span.reset if @span
end