codeguessing 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 341a84f6d5543b03ca44f91d6d6e5665c7e52fab
4
- data.tar.gz: 0ed379875167a232fb9c9c6803f3d663041cddfe
3
+ metadata.gz: 8bd4ea46cffddc9ac2c2b8f477b10e0b3954f77e
4
+ data.tar.gz: 78c4704c19a987743c9ef6e425c8dd59abf07010
5
5
  SHA512:
6
- metadata.gz: a28ad7756344e3c90188c851df4e7fa46d89f3a49bf891b6df9345fb1c29e8129fcc3ce227ce7cbfff974e7f7a5e54d210b3da2a59b7217d5d1fb219fc5743ba
7
- data.tar.gz: 6fd83fb0f85c1d59986ed7f08096a6c65a0ca91c9618240f404ba9ef5de0cebc703cbd5f474e3a4e637be6614baf4af444b9a9dd65fe00961d17517028b95eb7
6
+ metadata.gz: 33cdfbbf867d5a0b03a714aee3c2336ebd810db0db61cf081f8100dbe0722851d3e13ddabd3b6b41dddff9dce0ee1d47832758cb44af6256a02c5b35caf1df11
7
+ data.tar.gz: fb09f6de2f4a84390614d962822c1eb19b0ce0bf04082e44e70becfa12b83044c52ada50f54cc9cff7b4db8f715c2e49a24bae9c9e44793c0b5c766ab82632ea
@@ -4,6 +4,7 @@ module Codeguessing
4
4
 
5
5
  MAX_HINT = 2
6
6
  MAX_ATTEMPTS = 5
7
+ MAX_SIZE = 4
7
8
 
8
9
  def initialize(opt = {})
9
10
  @secret_code = opt[:secret_code] || random
@@ -15,6 +16,7 @@ module Codeguessing
15
16
 
16
17
  def guess(code)
17
18
  loose unless check?(use_attempt)
19
+ return false unless valid?(code)
18
20
  hash = {}
19
21
  res = ''
20
22
  remaine_chars = code
@@ -31,13 +33,13 @@ module Codeguessing
31
33
  end
32
34
  end
33
35
  res += hash.values.join('')
34
- win if res == '++++'
36
+ win if res == '+' * MAX_SIZE
35
37
  @answer = res
36
38
  end
37
39
 
38
40
  def hint
39
41
  res = ''
40
- need_index = rand(0...4)
42
+ need_index = rand(0...MAX_SIZE)
41
43
  secret_code.each_char.with_index do |char, index|
42
44
  if index == need_index
43
45
  res += char
@@ -69,7 +71,7 @@ module Codeguessing
69
71
  end
70
72
 
71
73
  def valid?(code)
72
- return true if code =~ /^[1-6]{4}$/s
74
+ return true if code =~ /^[1-6]{#{MAX_SIZE}}$/s
73
75
  false
74
76
  end
75
77
 
@@ -96,7 +98,7 @@ module Codeguessing
96
98
 
97
99
  def random
98
100
  code = ''
99
- 4.times { code += rand(1..6).to_s }
101
+ MAX_SIZE.times { code += rand(1..6).to_s }
100
102
  code
101
103
  end
102
104
 
@@ -1,3 +1,3 @@
1
1
  module Codeguessing
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeguessing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bezrukavyi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-06 00:00:00.000000000 Z
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize