Class: Inch::Evaluation::Role Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/evaluation/role.rb

Overview

This class is abstract.

Role objects are assigned to evaluations of code objects. They describe the object they are attached to.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, value = nil) ⇒ Role

Returns a new instance of Role

Parameters:

  • object (Codebase::Object)

    the object to evaluate

  • value (Float) (defaults to: nil)

    a score that might be added by this role


34
35
36
37
# File 'lib/inch/evaluation/role.rb', line 34

def initialize(object, value = nil)
  @object = object
  @value = value
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object


7
8
9
# File 'lib/inch/evaluation/role.rb', line 7

def object
  @object
end

Class Method Details

.applicable?(object) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
25
# File 'lib/inch/evaluation/role.rb', line 22

def applicable?(object)
  @applicable_procs ||= {}
  @applicable_procs[to_s].call(object)
end

.applicable_if(symbol = nil, &block) ⇒ Object


10
11
12
13
# File 'lib/inch/evaluation/role.rb', line 10

def applicable_if(symbol = nil, &block)
  @applicable_procs ||= {}
  @applicable_procs[to_s] = block || symbol.to_proc
end

.applicable_unless(symbol = nil, &block) ⇒ Object


15
16
17
18
19
20
# File 'lib/inch/evaluation/role.rb', line 15

def applicable_unless(symbol = nil, &block)
  @applicable_procs ||= {}
  @applicable_procs[to_s] = proc do |object|
    !(block || symbol.to_proc).call(object)
  end
end

.priority(value) ⇒ Object


27
28
29
# File 'lib/inch/evaluation/role.rb', line 27

def priority(value)
  define_method(:priority) { value }
end

Instance Method Details

#max_scoreFloat

Note:

Override this method to that a max_score for the evaluation.

Returns a maximal score for the object. The final score can not be higher than this.

Returns:

  • (Float)

43
44
# File 'lib/inch/evaluation/role.rb', line 43

def max_score
end

#min_scoreFloat

Note:

Override this method to that a min_score for the evaluation.

Returns a minimal score for the object. The final score can not be lower than this.

Returns:

  • (Float)

50
51
# File 'lib/inch/evaluation/role.rb', line 50

def min_score
end

#object_typeString

Returns the type of the object that is being evaluated.

Returns:

  • (String)

94
95
96
# File 'lib/inch/evaluation/role.rb', line 94

def object_type
  fail NotImplementedError
end

#potential_scoreFloat

Note:

Override this method to assign a potential score for the role

Returns a potential score that would be added to the overall score if the object had implemented the Role's subject.

Returns:

  • (Float)

See Also:

  • Role::Missing

68
69
70
# File 'lib/inch/evaluation/role.rb', line 68

def potential_score
  nil
end

#priorityFixnum

Note:

Override this method to assign a priority for the role

Returns a priority that will be added to the associated object's overall priority.

Returns:

  • (Fixnum)

77
78
79
# File 'lib/inch/evaluation/role.rb', line 77

def priority
  0
end

#scoreFloat

Note:

Override this method to assign a score for the role

Returns a score that will be added to the associated object's overall score.

Returns:

  • (Float)

58
59
60
# File 'lib/inch/evaluation/role.rb', line 58

def score
  @value.to_f
end

#suggestionString

Returns a suggestion to achieve the potential score that would be added to the overall score if the object had implemented the Role's subject.

Returns:

  • (String)

See Also:

  • Role::Missing

87
88
89
# File 'lib/inch/evaluation/role.rb', line 87

def suggestion
  nil
end