Class: CodebrekerManfly::CodeMatcher
- Inherits:
-
ValidatableEntity
- Object
- ValidatableEntity
- CodebrekerManfly::CodeMatcher
- Defined in:
- lib/codebreker_manfly/entities/code_matcher.rb
Constant Summary collapse
- STRONG_MATCH_SYMBOL =
'+'
- SOFT_MATCH_SYMBOL =
'-'
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
Attributes inherited from ValidatableEntity
Instance Method Summary collapse
- #codes_match? ⇒ Boolean
-
#initialize(secret_code, guess_code) ⇒ CodeMatcher
constructor
A new instance of CodeMatcher.
- #match_codes ⇒ Object
Methods inherited from ValidatableEntity
Methods included from Validator
#valid_class?, #valid_non_empty_string?, #valid_non_negative_integer?, #valid_only_numeric_string?, #valid_positive_integer?, #valid_range?, #valid_string_max_length?, #valid_string_min_length?
Constructor Details
#initialize(secret_code, guess_code) ⇒ CodeMatcher
Returns a new instance of CodeMatcher.
10 11 12 13 14 |
# File 'lib/codebreker_manfly/entities/code_matcher.rb', line 10 def initialize(secret_code, guess_code) super() @secret_code = secret_code @guess_code = guess_code end |
Instance Attribute Details
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
5 6 7 |
# File 'lib/codebreker_manfly/entities/code_matcher.rb', line 5 def answer @answer end |
Instance Method Details
#codes_match? ⇒ Boolean
23 24 25 |
# File 'lib/codebreker_manfly/entities/code_matcher.rb', line 23 def codes_match? @secret_code == @guess_code end |
#match_codes ⇒ Object
16 17 18 19 20 21 |
# File 'lib/codebreker_manfly/entities/code_matcher.rb', line 16 def match_codes secret_code = @secret_code.clone guess_code = @guess_code.clone strong_match(secret_code, guess_code) + soft_match(secret_code, guess_code) end |