Class: Lugg::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lugg/runner.rb

Overview

TODO:

extract conditions into individual objects.

The runner defines the command line interface for Lugg, using the other components and defining command line options and their implementations.

When creating a Runner object, you pass it your option flags (typically ARGV). You can then apply its conditions to an IO object (typically ARGF).

Instance Method Summary collapse

Constructor Details

#initialize(flags = [], filter = Filter.new) ⇒ Runner

Returns a new instance of Runner.



21
22
23
24
25
# File 'lib/lugg/runner.rb', line 21

def initialize(flags = [], filter = Filter.new)
  @filter = filter
  reset
  options.parse!(flags)
end

Instance Method Details

#add_clause(&block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/lugg/runner.rb', line 33

def add_clause(&block)
  if combine_clauses?
    prev_block = @last_block
    filter.use { |r| prev_block.call(r) && block.call(r) }
    reset
  else
    filter.use(&block)
    @last_block = block
  end
end

#combine_nextObject



44
45
46
# File 'lib/lugg/runner.rb', line 44

def combine_next
  @combine = true
end

#run(io) ⇒ Object



27
28
29
30
31
# File 'lib/lugg/runner.rb', line 27

def run(io)
  filter.call(Streamer.new(io).records).each do |request|
    puts request.source
  end
end