Skip to content

Instantly share code, notes, and snippets.

@szymonbaranowski
Last active March 12, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szymonbaranowski/ae38b9850ae2d621c8c0 to your computer and use it in GitHub Desktop.
Save szymonbaranowski/ae38b9850ae2d621c8c0 to your computer and use it in GitHub Desktop.
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