Class: Saper::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/saper/core/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stacks = []) ⇒ Result


11
12
13
14
15
16
17
18
# File 'lib/saper/core/result.rb', line 11

def initialize(stacks = [])
  started   = Time.now
  @stacks   = stacks.to_a
  @duration = Time.now - started
  if block_given?
    yield self
  end
end

Instance Attribute Details

#durationObject (readonly)


8
9
10
# File 'lib/saper/core/result.rb', line 8

def duration
  @duration
end

#stacksObject (readonly)


5
6
7
# File 'lib/saper/core/result.rb', line 5

def stacks
  @stacks
end

Instance Method Details

#bytes_receivedObject


31
32
33
# File 'lib/saper/core/result.rb', line 31

def bytes_received
  browser.received
end

#bytes_sentObject


26
27
28
# File 'lib/saper/core/result.rb', line 26

def bytes_sent
  browser.sent
end

#eachObject


55
56
57
# File 'lib/saper/core/result.rb', line 55

def each
  filtered_stacks.each { |stack| stack.result.is_a?(Saper::Item) ? yield(stack.result.to_native) : yield(stack.result) }
end

#failure?Boolean


41
42
43
# File 'lib/saper/core/result.rb', line 41

def failure?
  filtered_stacks.all?(&:error?)
end

#http_requestsObject


21
22
23
# File 'lib/saper/core/result.rb', line 21

def http_requests
  browser.requests
end

#multiple?Boolean


51
52
53
# File 'lib/saper/core/result.rb', line 51

def multiple?
  size > 1
end

#serializeObject


85
86
87
# File 'lib/saper/core/result.rb', line 85

def serialize
  multiple? ? to_serialized_array : to_serialized_array.first
end

#sizeObject


46
47
48
# File 'lib/saper/core/result.rb', line 46

def size
  stacks.size
end

#success?Boolean


36
37
38
# File 'lib/saper/core/result.rb', line 36

def success?
  not failure?
end

#to_json(*args) ⇒ Array

Returns runtime results as JSON.


91
92
93
# File 'lib/saper/core/result.rb', line 91

def to_json(*args)
  JSON.dump(serialize)
end

#to_nativeObject


80
81
82
# File 'lib/saper/core/result.rb', line 80

def to_native
  multiple? ? to_native_array : to_native_array.first
end

#to_native_arrayObject


65
66
67
# File 'lib/saper/core/result.rb', line 65

def to_native_array
  to_saper_array.map { |i| i.is_a?(Saper::Item) ? i.to_native : i }
end

#to_saperObject


75
76
77
# File 'lib/saper/core/result.rb', line 75

def to_saper
  multiple? ? to_saper_array : to_saper_array.first
end

#to_saper_arrayObject


60
61
62
# File 'lib/saper/core/result.rb', line 60

def to_saper_array
  filtered_stacks.map(&:result)
end

#to_serialized_arrayObject


70
71
72
# File 'lib/saper/core/result.rb', line 70

def to_serialized_array
  to_saper_array.map { |i| i.is_a?(Saper::Item) ? i.serialize : i }
end