Class: Fix::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/fix/subject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, *args) ⇒ Subject

Returns a new instance of Subject.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fix/subject.rb', line 5

def initialize input, *args
  @args         = args
  @error        = nil
  @implemented  = nil
  @last_arg     = -1

  begin
    @cache_value = params.inject(input) do |mem, param|
      @implemented  = mem.respond_to? param.first, false
      @last_arg     = @last_arg.next

      mem.public_send(*param)
    end

    @last_arg = @last_arg.next
  rescue => @error
  end

  freeze
end

Instance Attribute Details

#last_argObject (readonly)

Returns the value of attribute last_arg.



3
4
5
# File 'lib/fix/subject.rb', line 3

def last_arg
  @last_arg
end

Instance Method Details

#actualObject



26
27
28
29
30
31
32
# File 'lib/fix/subject.rb', line 26

def actual
  if @error.nil?
    @cache_value.public_send(*challenge)
  else
    raise @error
  end
end

#challengeObject



38
39
40
# File 'lib/fix/subject.rb', line 38

def challenge
  @args.last
end

#implemented?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fix/subject.rb', line 42

def implemented?
  @implemented && @error.nil? && @cache_value.respond_to?(challenge.first, false)
end

#paramsObject



34
35
36
# File 'lib/fix/subject.rb', line 34

def params
  @args[0..-2]
end