Class: CMSScanner::Finders::Confidence

Inherits:
Numeric
  • Object
show all
Defined in:
lib/cms_scanner/finders/confidence.rb

Overview

Confidence

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Numeric

#bytes_to_human

Constructor Details

#initialize(value) ⇒ Confidence

Returns a new instance of Confidence.



7
8
9
# File 'lib/cms_scanner/finders/confidence.rb', line 7

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/cms_scanner/finders/confidence.rb', line 5

def value
  @value
end

Instance Method Details

#+(other) ⇒ Confidence

TODO: rework the formula which is weak when the value to add is < the current confidence e.g: 90 + 50 + 30 => 82

Parameters:

Returns:



17
18
19
20
21
22
23
24
25
# File 'lib/cms_scanner/finders/confidence.rb', line 17

def +(other)
  return Confidence.new(100) if @value == 100

  to_add    = other_value(other)
  new_value = (@value + to_add) / 1.5
  new_value = 100 if new_value > 100 || to_add == 100

  Confidence.new(new_value.floor)
end

#<(other) ⇒ Object

Parameters:



55
56
57
# File 'lib/cms_scanner/finders/confidence.rb', line 55

def <(other)
  @value < other_value(other)
end

#<=(other) ⇒ Object

Parameters:



60
61
62
# File 'lib/cms_scanner/finders/confidence.rb', line 60

def <=(other)
  @value <= other_value(other)
end

#<=>(other) ⇒ Object

Parameters:



75
76
77
# File 'lib/cms_scanner/finders/confidence.rb', line 75

def <=>(other)
  @value <=> other_value(other)
end

#==(other) ⇒ Object

Parameters:



45
46
47
# File 'lib/cms_scanner/finders/confidence.rb', line 45

def ==(other)
  @value == other_value(other)
end

#>(other) ⇒ Object

Parameters:



65
66
67
# File 'lib/cms_scanner/finders/confidence.rb', line 65

def >(other)
  @value > other_value(other)
end

#>=(other) ⇒ Object

Parameters:



70
71
72
# File 'lib/cms_scanner/finders/confidence.rb', line 70

def >=(other)
  @value >= other_value(other)
end

#eql?(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


50
51
52
# File 'lib/cms_scanner/finders/confidence.rb', line 50

def eql?(other)
  @value.eql?(other_value(other))
end

#other_value(other) ⇒ Object

Parameters:



40
41
42
# File 'lib/cms_scanner/finders/confidence.rb', line 40

def other_value(other)
  other.is_a?(Confidence) ? other.value : other
end

#to_jsonObject



35
36
37
# File 'lib/cms_scanner/finders/confidence.rb', line 35

def to_json
  @value.to_json
end

#to_sObject

Convenient Methods

:nocov:



31
32
33
# File 'lib/cms_scanner/finders/confidence.rb', line 31

def to_s
  @value.to_s
end