Class: Inch::Evaluation::Role Abstract
- Inherits:
-
Object
- Object
- Inch::Evaluation::Role
- Defined in:
- lib/inch/evaluation/role.rb
Overview
Role objects are assigned to evaluations of code objects. They describe the object they are attached to.
Direct Known Subclasses
Language::Elixir::Evaluation::Role::Base, Language::Nodejs::Evaluation::Role::Base, Language::Ruby::Evaluation::Role::Base
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
- .applicable?(object) ⇒ Boolean
- .applicable_if(symbol = nil, &block) ⇒ Object
- .applicable_unless(symbol = nil, &block) ⇒ Object
- .priority(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(object, value = nil) ⇒ Role
constructor
A new instance of Role.
-
#max_score ⇒ Float
Returns a maximal score for the object.
-
#min_score ⇒ Float
Returns a minimal score for the object.
-
#object_type ⇒ String
Returns the type of the
object
that is being evaluated. -
#potential_score ⇒ Float
Returns a potential score that would be added to the overall score if the object had implemented the Role’s subject.
-
#priority ⇒ Fixnum
Returns a priority that will be added to the associated object’s overall priority.
-
#score ⇒ Float
Returns a score that will be added to the associated object’s overall score.
-
#suggestion ⇒ String
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.
Constructor Details
#initialize(object, value = nil) ⇒ Role
Returns a new instance of 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
#object ⇒ Object (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
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_score ⇒ Float
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.
43 44 |
# File 'lib/inch/evaluation/role.rb', line 43 def max_score end |
#min_score ⇒ Float
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.
50 51 |
# File 'lib/inch/evaluation/role.rb', line 50 def min_score end |
#object_type ⇒ String
Returns the type of the object
that is being evaluated.
94 95 96 |
# File 'lib/inch/evaluation/role.rb', line 94 def object_type fail NotImplementedError end |
#potential_score ⇒ Float
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.
68 69 70 |
# File 'lib/inch/evaluation/role.rb', line 68 def potential_score nil end |
#priority ⇒ Fixnum
Override this method to assign a priority for the role
Returns a priority that will be added to the associated object’s overall priority.
77 78 79 |
# File 'lib/inch/evaluation/role.rb', line 77 def priority 0 end |
#score ⇒ Float
Override this method to assign a score for the role
Returns a score that will be added to the associated object’s overall score.
58 59 60 |
# File 'lib/inch/evaluation/role.rb', line 58 def score @value.to_f end |
#suggestion ⇒ String
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.
87 88 89 |
# File 'lib/inch/evaluation/role.rb', line 87 def suggestion nil end |