Class: Chirp::LineProcessor
- Inherits:
-
Object
- Object
- Chirp::LineProcessor
- Defined in:
- lib/chirp/application.rb
Constant Summary collapse
- DEFAULT_ACTION =
lambda { puts(line) }
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(context, options = {}, &block) ⇒ LineProcessor
constructor
A new instance of LineProcessor.
- #reset ⇒ Object
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, ={}, &block) @context = context @expression = [:expr] @pattern = [:pattern] @match = [:match] @number = [:number] if [:start] @span = Span.new([:start], [:end]) else @span=nil end @options = @block = block || DEFAULT_ACTION end |
Instance Method Details
#execute ⇒ Object
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 |
#reset ⇒ Object
110 111 112 |
# File 'lib/chirp/application.rb', line 110 def reset @span.reset if @span end |