Class: Dat::Science::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/dat/science/result.rb

Overview

Internal. The output of running of an observed behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment, value, duration, exception) ⇒ Result

Returns a new instance of Result.



11
12
13
14
15
16
# File 'lib/dat/science/result.rb', line 11

def initialize(experiment, value, duration, exception)
  @duration   = duration
  @exception  = exception
  @experiment = experiment
  @value      = value
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/dat/science/result.rb', line 6

def duration
  @duration
end

#exceptionObject (readonly)

Returns the value of attribute exception.



7
8
9
# File 'lib/dat/science/result.rb', line 7

def exception
  @exception
end

#experimentObject (readonly)

Returns the value of attribute experiment.



8
9
10
# File 'lib/dat/science/result.rb', line 8

def experiment
  @experiment
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/dat/science/result.rb', line 9

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dat/science/result.rb', line 18

def ==(other)
  return false unless other.is_a? Dat::Science::Result

  values_are_equal = experiment.compare(other.value, value)
  both_raised      = other.raised? && raised?
  neither_raised   = !other.raised? && !raised?

  exceptions_are_equivalent =
    both_raised && other.exception.class == self.exception.class &&
    other.exception.message == self.exception.message

  (values_are_equal && neither_raised) ||
    (both_raised && exceptions_are_equivalent)
end

#hashObject



33
34
35
# File 'lib/dat/science/result.rb', line 33

def hash
  exception ^ value
end

#payloadObject



37
38
39
40
41
42
43
# File 'lib/dat/science/result.rb', line 37

def payload
  {
    :duration  => duration,
    :exception => exception,
    :value     => experiment.clean(value)
  }
end

#raised?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dat/science/result.rb', line 45

def raised?
  !!exception
end