Class: CodebrekerManfly::CodeMatcher

Inherits:
ValidatableEntity show all
Defined in:
lib/codebreker_manfly/entities/code_matcher.rb

Constant Summary collapse

STRONG_MATCH_SYMBOL =
'+'
SOFT_MATCH_SYMBOL =
'-'

Instance Attribute Summary collapse

Attributes inherited from ValidatableEntity

#errors

Instance Method Summary collapse

Methods inherited from ValidatableEntity

#valid?

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

#answerObject (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

Returns:

  • (Boolean)


23
24
25
# File 'lib/codebreker_manfly/entities/code_matcher.rb', line 23

def codes_match?
  @secret_code == @guess_code
end

#match_codesObject



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