new_super_codebreaker_2021 0.4.5 → 0.4.6

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
  SHA256:
3
- metadata.gz: e6e66f5272359e959f412ca6dc0d7363d7ede198844dcdbcd9878701b90347cf
4
- data.tar.gz: 450d2f983d577a9ccc0c979cb29b8ae8364c3542d809db80dec89482910604c5
3
+ metadata.gz: 81df7f5993ddc2b124bf20ac2632b1c6908a785076afacb407e2a3dcf14b7c11
4
+ data.tar.gz: a9246bff8d86887c221547198b93f8716297989de63ea77a5baa6e2a5c3ff87c
5
5
  SHA512:
6
- metadata.gz: 15def3bd39bf2b810370cf2310d1ac613013a3179da4565459214f2533fe057222b16b4f27bbea189e236f13f4eb022cce560c8983420c0f5a7fa41ff89392f1
7
- data.tar.gz: 12586743080a5fc9dff5b8e32155f327a95de55ca7355f982f70b530f548daadc8098c268777a78bc6e35a631d7febe1e8d1da309fd933ca272863e388640fae
6
+ metadata.gz: c8c12e16606143f316f87d56e5b92fe5a76ea1fffbe4f4e7c5ea5ca07dd16905dc8d0f35347bfc81c5ad3e4eddee3f435486e1ccfe77682ccd54ca47e9642f5e
7
+ data.tar.gz: eb64b063703142840276857ebf202e97ed4c2c1e31743c7636cc0f0f0759b69ec71626b0a00b77a8afd7e0ab166940c4a3680238d96f1501bbe838919fe0bafa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- new_super_codebreaker_2021 (0.4.4)
4
+ new_super_codebreaker_2021 (0.4.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -64,7 +64,7 @@ PLATFORMS
64
64
 
65
65
  DEPENDENCIES
66
66
  fasterer (~> 0.9.0)
67
- ffaker
67
+ ffaker (~> 2.19.0)
68
68
  new_super_codebreaker_2021!
69
69
  rake (~> 13.0)
70
70
  rspec (~> 3.10.0)
data/lib/loader.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+ require_relative 'new_super_codebreaker_2021/user'
3
+ require_relative 'new_super_codebreaker_2021/show_content'
4
+ require_relative 'new_super_codebreaker_2021/db_methods'
5
+ require_relative 'new_super_codebreaker_2021/validate'
6
+ require_relative 'new_super_codebreaker_2021/new_super_codebreaker_2021'
7
+ require_relative 'new_super_codebreaker_2021/game'
8
+ require_relative 'new_super_codebreaker_2021/version'
@@ -0,0 +1,17 @@
1
+ module NewSuperCodebreaker2021
2
+ module DBMethods
3
+ def save(user, file)
4
+ rating = load_file(file)
5
+ rating.push(user)
6
+ File.open(file, 'w') do |filename|
7
+ YAML.dump(rating, filename)
8
+ end
9
+ end
10
+
11
+ def load_file(file)
12
+ YAML.load_file(file)
13
+ rescue Errno::ENOENT
14
+ []
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,12 @@
1
- require 'yaml'
2
- require_relative 'validate'
3
- require_relative 'show_content'
4
- require_relative 'db_methods'
5
- require_relative 'user'
1
+ require_relative '../loader'
2
+
6
3
  module NewSuperCodebreaker2021
7
4
  class Game
8
- attr_reader :code
9
-
10
- include Validate
11
- include ShowContent
12
5
  include DBMethods
6
+ include ShowContent
7
+ include Validate
8
+
9
+ attr_reader :code
13
10
 
14
11
  def initialize
15
12
  @code = generate_code
@@ -1,6 +1,3 @@
1
- require_relative 'new_super_codebreaker_2021/version'
2
- require 'game'
3
-
4
1
  module NewSuperCodebreaker2021
5
2
  class Error < StandardError; end
6
3
  end
@@ -0,0 +1,10 @@
1
+ module NewSuperCodebreaker2021
2
+ module ShowContent
3
+ def show_stats(file)
4
+ data = YAML.load_file(file) || []
5
+ data.sort_by! { |game| [-game.difficulty, game.attempts_used, game.hints_used] }
6
+ rescue Errno::ENOENT
7
+ []
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module NewSuperCodebreaker2021
2
+ class User
3
+ attr_reader :name, :difficulty, :hints_total, :attempts_total
4
+ attr_accessor :hints_used, :attempts_used
5
+
6
+ DIFFICULTY = {
7
+ easy: { attempts: 15, hints: 2 },
8
+ medium: { attempts: 10, hints: 1 },
9
+ hell: { attempts: 5, hints: 1 }
10
+ }.freeze
11
+
12
+ def initialize(name, difficulty)
13
+ @name = name
14
+ @difficulty = difficulty
15
+ @hints_used = 0
16
+ @attempts_used = 0
17
+ set_total_fields
18
+ end
19
+
20
+ private
21
+
22
+ def set_total_fields
23
+ difficulty = DIFFICULTY.keys[@difficulty]
24
+ @hints_total = DIFFICULTY[difficulty][:hints]
25
+ @attempts_total = DIFFICULTY[difficulty][:attempts]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ module NewSuperCodebreaker2021
2
+ module Validate
3
+ def validate_name(name)
4
+ name if valid_name?(name)
5
+ end
6
+
7
+ def validate_user_code(us_code)
8
+ arr_code = split_to_integer_array(us_code)
9
+ return unless valid_number?(arr_code)
10
+
11
+ arr_code
12
+ end
13
+
14
+ def check_input(input, command_list)
15
+ return unless valid_input?(input, command_list)
16
+
17
+ input.to_sym
18
+ end
19
+
20
+ private
21
+
22
+ def valid_input?(input, command_list)
23
+ input.to_i.zero? && command_list.include?(input.to_sym)
24
+ end
25
+
26
+ def valid_number?(arr_code)
27
+ arr_code && check_code_length?(arr_code) && check_numbers?(arr_code)
28
+ end
29
+
30
+ def split_to_integer_array(code)
31
+ code.chars.map!(&:to_i) if integer?(code)
32
+ end
33
+
34
+ def integer?(code)
35
+ code.to_i.to_s == code
36
+ end
37
+
38
+ def check_code_length?(code)
39
+ code.length == 4
40
+ end
41
+
42
+ def check_numbers?(code)
43
+ code.all? { |value| value.between?(1, 6) }
44
+ end
45
+
46
+ def valid_name?(name)
47
+ name.length >= 3 && name.length <= 20
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module NewSuperCodebreaker2021
4
- VERSION = '0.4.5'
2
+ VERSION = '0.4.6'.freeze
5
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_super_codebreaker_2021
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nazar Dakhno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2021-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -123,13 +123,14 @@ files:
123
123
  - Rakefile
124
124
  - bin/console
125
125
  - bin/setup
126
- - lib/db_methods.rb
127
- - lib/game.rb
128
- - lib/new_super_codebreaker_2021.rb
126
+ - lib/loader.rb
127
+ - lib/new_super_codebreaker_2021/db_methods.rb
128
+ - lib/new_super_codebreaker_2021/game.rb
129
+ - lib/new_super_codebreaker_2021/new_super_codebreaker_2021.rb
130
+ - lib/new_super_codebreaker_2021/show_content.rb
131
+ - lib/new_super_codebreaker_2021/user.rb
132
+ - lib/new_super_codebreaker_2021/validate.rb
129
133
  - lib/new_super_codebreaker_2021/version.rb
130
- - lib/show_content.rb
131
- - lib/user.rb
132
- - lib/validate.rb
133
134
  homepage: https://rubygems.org/gems/new_super_codebreaker_2021
134
135
  licenses:
135
136
  - MIT
data/lib/db_methods.rb DELETED
@@ -1,15 +0,0 @@
1
- module DBMethods
2
- def save(user, file)
3
- rating = load_file(file)
4
- rating.push(user)
5
- File.open(file, 'w') do |filename|
6
- YAML.dump(rating, filename)
7
- end
8
- end
9
-
10
- def load_file(file)
11
- YAML.load_file(file)
12
- rescue Errno::ENOENT
13
- []
14
- end
15
- end
data/lib/show_content.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'terminal-table'
2
-
3
- module ShowContent
4
- def show_stats(file)
5
- data = YAML.load_file(file) || []
6
- data.sort_by! { |game| [-game.difficulty, game.attempts_used, game.hints_used] }
7
- rescue Errno::ENOENT
8
- []
9
- end
10
- end
data/lib/user.rb DELETED
@@ -1,28 +0,0 @@
1
- require_relative 'show_content'
2
-
3
- class User
4
- attr_reader :name, :difficulty, :hints_total, :attempts_total
5
- attr_accessor :hints_used, :attempts_used
6
-
7
- DIFFICULTY = {
8
- easy: { attempts: 15, hints: 2 },
9
- medium: { attempts: 10, hints: 1 },
10
- hell: { attempts: 5, hints: 1 }
11
- }.freeze
12
-
13
- def initialize(name, difficulty)
14
- @name = name
15
- @difficulty = difficulty
16
- @hints_used = 0
17
- @attempts_used = 0
18
- set_total_fields
19
- end
20
-
21
- private
22
-
23
- def set_total_fields
24
- difficulty = DIFFICULTY.keys[@difficulty]
25
- @hints_total = DIFFICULTY[difficulty][:hints]
26
- @attempts_total = DIFFICULTY[difficulty][:attempts]
27
- end
28
- end
data/lib/validate.rb DELETED
@@ -1,48 +0,0 @@
1
- module Validate
2
- def validate_name(name)
3
- name if valid_name?(name)
4
- end
5
-
6
- def validate_user_code(us_code)
7
- arr_code = split_to_integer_array(us_code)
8
- return unless valid_number?(arr_code)
9
-
10
- arr_code
11
- end
12
-
13
- def check_input(input, command_list)
14
- return unless valid_input?(input, command_list)
15
-
16
- input.to_sym
17
- end
18
-
19
- private
20
-
21
- def valid_input?(input, command_list)
22
- input.to_i.zero? && command_list.include?(input.to_sym)
23
- end
24
-
25
- def valid_number?(arr_code)
26
- arr_code && check_code_length?(arr_code) && check_numbers?(arr_code)
27
- end
28
-
29
- def split_to_integer_array(code)
30
- code.chars.map!(&:to_i) if integer?(code)
31
- end
32
-
33
- def integer?(code)
34
- code.to_i.to_s == code
35
- end
36
-
37
- def check_code_length?(code)
38
- code.length == 4
39
- end
40
-
41
- def check_numbers?(code)
42
- code.all? { |value| value.between?(1, 6) }
43
- end
44
-
45
- def valid_name?(name)
46
- name.length >= 3 && name.length <= 20
47
- end
48
- end