Class: IdentityParade::Matchers::NumericMatcher

Inherits:
IdentityParade::Matcher show all
Defined in:
lib/identity_parade/matchers/numeric_matcher.rb

Overview

This matcher checks the similarity of two numerics.

Direct Known Subclasses

FloatMatcher, IntegerMatcher

Instance Attribute Summary

Attributes inherited from IdentityParade::Matcher

#left, #right

Instance Method Summary collapse

Methods inherited from IdentityParade::Matcher

#initialize

Constructor Details

This class inherits a constructor from IdentityParade::Matcher

Instance Method Details

#floatsObject



20
21
22
# File 'lib/identity_parade/matchers/numeric_matcher.rb', line 20

def floats
  [left.to_f, right.to_f]
end

#maxObject



12
13
14
# File 'lib/identity_parade/matchers/numeric_matcher.rb', line 12

def max
  floats.max
end

#minObject



16
17
18
# File 'lib/identity_parade/matchers/numeric_matcher.rb', line 16

def min
  floats.min
end

#scoreObject



5
6
7
8
9
10
# File 'lib/identity_parade/matchers/numeric_matcher.rb', line 5

def score
  return 1 if max == min
  return 0 if max.zero?

  min / max
end