Class: Inch::Evaluation::Role::Base Abstract

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

Overview

This class is abstract.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, value = nil) ⇒ Base

Returns a new instance of Base.



29
30
31
32
# File 'lib/inch/evaluation/role/base.rb', line 29

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

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

Class Method Details

.applicable?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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



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

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

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



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

def applicable_unless(symbol = nil, &block)
  @applicable_procs ||= {}
  @applicable_procs[to_s] = proc do |object|
    !(block || symbol.to_proc).call(object)
  end
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)


38
39
# File 'lib/inch/evaluation/role/base.rb', line 38

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)


45
46
# File 'lib/inch/evaluation/role/base.rb', line 45

def min_score
end

#object_typeObject



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

def object_type
  object.class.to_s.split('::').last.gsub(/Object$/, '').downcase
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:



63
64
65
# File 'lib/inch/evaluation/role/base.rb', line 63

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)


72
73
74
# File 'lib/inch/evaluation/role/base.rb', line 72

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)


53
54
55
# File 'lib/inch/evaluation/role/base.rb', line 53

def score
  @value.to_f
end

#suggestionFloat

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:

  • (Float)

See Also:



82
83
84
# File 'lib/inch/evaluation/role/base.rb', line 82

def suggestion
  nil
end