-
-
Save szymonbaranowski/ae38b9850ae2d621c8c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Services | |
module Validators | |
class Likelihood | |
RESPONSES = { | |
unknown: 0, | |
very_unlikely: 1, | |
unlikely: 2, | |
possible: 3, | |
likely: 4, | |
very_likely: 5, | |
}.freeze | |
private_constant :RESPONSES | |
def initialize(response, threshold) | |
@response, @threshold = response, threshold | |
end | |
def call | |
value_for(@response) > value_for(@threshold) | |
end | |
private | |
def value_for(response) | |
RESPONSES.fetch(response.downcase.to_sym) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment