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
# File 'lib/fix/subject.rb', line 5

def initialize input, *args
  @args         = args
  @error        = nil
  @implemented  = true
  @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.__send__(*param)
    end

    @last_arg = @last_arg.next
  rescue => @error
  end
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



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

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

#challengeObject



36
37
38
# File 'lib/fix/subject.rb', line 36

def challenge
  @args.last
end

#implemented?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fix/subject.rb', line 40

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

#paramsObject



32
33
34
# File 'lib/fix/subject.rb', line 32

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