Class: Tryouts::Drill::Reality

Inherits:
Response
  • Object
show all
Defined in:
lib/tryouts/drill/reality.rb

Overview

Reality

Contains the actual response of a Drill

Instance Attribute Summary collapse

Attributes inherited from Response

#format, #output

Instance Method Summary collapse

Methods inherited from Response

compare, compare_string

Constructor Details

#initializeReality

Returns a new instance of Reality.



16
17
18
# File 'lib/tryouts/drill/reality.rb', line 16

def initialize
  @stash = Tryouts::HASH_TYPE.new
end

Instance Attribute Details

#commandObject

For :cli drills only. Contains the shell command string.



15
16
17
# File 'lib/tryouts/drill/reality.rb', line 15

def command
  @command
end

#ecodeObject

Returns the value of attribute ecode.



12
13
14
# File 'lib/tryouts/drill/reality.rb', line 12

def ecode
  @ecode
end

#errorObject

Returns the value of attribute error.



10
11
12
# File 'lib/tryouts/drill/reality.rb', line 10

def error
  @error
end

#etypeObject

Returns the value of attribute etype.



13
14
15
# File 'lib/tryouts/drill/reality.rb', line 13

def etype
  @etype
end

#stashObject

An ordered hash taken from the DrillContext that created this Reality.



9
10
11
# File 'lib/tryouts/drill/reality.rb', line 9

def stash
  @stash
end

#traceObject

Returns the value of attribute trace.



11
12
13
# File 'lib/tryouts/drill/reality.rb', line 11

def trace
  @trace
end

Instance Method Details

#==(dream) ⇒ Object



20
21
22
# File 'lib/tryouts/drill/reality.rb', line 20

def ==(dream)
  Response.compare(dream, self)
end

#comparison_value(dream) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tryouts/drill/reality.rb', line 24

def comparison_value(dream)
  case dream.format
  when :proc
    test = dream.output
    (test.arity > 0 ? test.call(@output) : test.call)
  when :exception
    @etype
  when :respond_to?, :is_a?, :kind_of?, :grep
    @output.send(dream.format, dream.output)
  when nil
    @output
  else 
    return nil if @output.nil? 
    
    if !dream.format.is_a?(Symbol)
      "This dream format is not a Symbol: #{dream.format}"
    elsif @output.respond_to?(dream.format)
      @output.send(dream.format)
    else
      @output
    end
  end
end