Class: Crabfarm::Live::ReducerRunnerDirect

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/live/reducer_runner_direct.rb

Instance Method Summary collapse

Constructor Details

#initialize(_manager, _snapshot, _target, _params) ⇒ ReducerRunnerDirect

Returns a new instance of ReducerRunnerDirect.



8
9
10
11
12
13
# File 'lib/crabfarm/live/reducer_runner_direct.rb', line 8

def initialize(_manager, _snapshot, _target, _params)
  @manager = _manager
  @snapshot = _snapshot
  @target = _target
  @params = _params
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
# File 'lib/crabfarm/live/reducer_runner_direct.rb', line 15

def execute
  raise ArgumentError.new 'Must provide a snapshot to execute reducer' if @snapshot.nil?

  snapshot_path = @target.snapshot_path @snapshot
  raise ArgumentError.new "Snapshot does not exist #{snapshot_path}" unless File.exist? snapshot_path

  @reducer = Factories::SnapshotReducer.build @target, snapshot_path, (@params || {})
  @elapsed = Benchmark.measure { @reducer.run }
end

#show_resultsObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/crabfarm/live/reducer_runner_direct.rb', line 25

def show_results
  @manager.show_message(
    :neutral,
    'Reducing completed!',
    "The page was parsed in #{@elapsed.real} seconds",
    @reducer.to_json,
    :json
  )

  Utils::Console.json_result @reducer
  Utils::Console.info "Completed in #{@elapsed.real} s"
end