Class: ErrorToCommunicate::Heuristic::WrongNumberOfArguments

Inherits:
ErrorToCommunicate::Heuristic show all
Defined in:
lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb

Instance Attribute Summary collapse

Attributes inherited from ErrorToCommunicate::Heuristic

#einfo, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ErrorToCommunicate::Heuristic

#backtrace, #classname, #message, #semantic_backtrace, #semantic_summary

Constructor Details

#initializeWrongNumberOfArguments

Returns a new instance of WrongNumberOfArguments.



13
14
15
16
17
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 13

def initialize(*)
  super
  self.num_received, self.num_expected = self.class.extract_from(message)
  self.explanation = 'Wrong number of arguments'
end

Instance Attribute Details

#explanationObject

Returns the value of attribute explanation.



11
12
13
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11

def explanation
  @explanation
end

#num_expectedObject

Returns the value of attribute num_expected.



11
12
13
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11

def num_expected
  @num_expected
end

#num_receivedObject

Returns the value of attribute num_received.



11
12
13
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11

def num_received
  @num_received
end

Class Method Details

.for?(einfo) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 7

def self.for?(einfo)
  extract_from einfo.message
end

Instance Method Details

#semantic_explanationObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 19

def semantic_explanation
  [ :message,
    [ [:explanation, explanation],
      [:context, ' (given '],
      [:details, num_received],
      [:context, ', expected '],
      [:details, num_expected],
      [:context, ')'],
    ]
  ]
end

#semantic_infoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 31

def semantic_info
  if backtrace.length == 0
    [:context, "Couldn\'t find anything interesting ¯\\_(ツ)_/¯\n"]
  elsif backtrace.length == 1
    [:heuristic, [:code, {
      location:  backtrace[0],
      highlight: backtrace[0].label,
      context:   (-5..5),
      emphasis:  :code,
    }]]
  else
    [:heuristic, [
      [:code, {
        location:  backtrace[0],
        highlight: backtrace[0].label,
        context:   0..5,
        message:   "EXPECTED #{num_expected}",
        emphasis:  :code,
      }],

      [:code, {
        location:  backtrace[1],
        highlight: backtrace[0].label,
        context:   -5..5,
        message:   "SENT #{num_received}",
        emphasis:  :code,
      }],
    ]]
  end
end